From 7336bcdd25c8f4089e14ca4341f7ef115836ed98 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 2 Aug 2023 09:57:47 -0700 Subject: [PATCH] Allow setting a configuration to TestableResources This allows me to specify different configurations so that I can write a test for validating behavior with different configs. Test: atest this with my other CLs Bug: 283910436 Change-Id: I2f21b03b57a7b292384380aedab27769f09f22aa --- .../src/android/testing/TestableResources.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testables/src/android/testing/TestableResources.java b/tests/testables/src/android/testing/TestableResources.java index 27d5b66b355e6..0ec106e329f62 100644 --- a/tests/testables/src/android/testing/TestableResources.java +++ b/tests/testables/src/android/testing/TestableResources.java @@ -15,9 +15,11 @@ package android.testing; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; import android.content.Context; +import android.content.res.Configuration; import android.content.res.Resources; import android.util.Log; import android.util.SparseArray; @@ -53,6 +55,16 @@ public class TestableResources { return mResources; } + /** + * Sets a configuration for {@link #getResources()} to return to allow custom configs to + * be set and tested. + * + * @param configuration the configuration to return from resources. + */ + public void overrideConfiguration(Configuration configuration) { + when(mResources.getConfiguration()).thenReturn(configuration); + } + /** * Sets the return value for the specified resource id. *