From d3582b8a658c658a0543506ffa9542db3e7c2032 Mon Sep 17 00:00:00 2001 From: ZSmallX Date: Sun, 3 Apr 2022 11:33:49 +0800 Subject: [PATCH 01/10] Fixed PFD testGetFd_canRead test failed on macOS. Used `new FileInputStream(FileDescriptor)` instead of `new FileInputStream(String)`. Avoid depending on Linux file system details, and make full use of Java cross platform feature. Notes: it can still run failed on Windows. Signed-off-by: ZSmallX --- .../shadows/ShadowParcelFileDescriptorTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowParcelFileDescriptorTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowParcelFileDescriptorTest.java index 3a1f65d0f3c..8a6e4747f38 100644 --- a/robolectric/src/test/java/org/robolectric/shadows/ShadowParcelFileDescriptorTest.java +++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowParcelFileDescriptorTest.java @@ -8,6 +8,7 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.io.File; +import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -16,6 +17,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.util.ReflectionHelpers; @RunWith(AndroidJUnit4.class) public class ShadowParcelFileDescriptorTest { @@ -261,7 +263,12 @@ public void testGetFd_canRead() throws IOException { pfd = ParcelFileDescriptor.open(readOnlyFile, ParcelFileDescriptor.MODE_READ_ONLY); int fd = pfd.getFd(); assertThat(fd).isGreaterThan(0); - FileInputStream is = new FileInputStream(new File("/proc/self/fd/" + fd)); + + final FileDescriptor fileDescriptor = pfd.getFileDescriptor(); + assertThat(fileDescriptor.valid()).isTrue(); + assertThat(fd).isEqualTo(ReflectionHelpers.getField(fileDescriptor, "fd")); + + FileInputStream is = new FileInputStream(fileDescriptor); assertThat(is.read()).isEqualTo(READ_ONLY_FILE_CONTENTS); is.close(); } From faef65b31971ccf9241aa57d24fb15fc470bfa50 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 27 Mar 2022 12:50:02 +0800 Subject: [PATCH 02/10] Bump actions --- .github/workflows/build_native_runtime.yml | 15 +++++----- .github/workflows/check_aggregateDocs.yml | 4 +-- .github/workflows/check_code_formatting.yml | 5 ++-- .../workflows/gradle_wrapper_validation.yml | 2 +- .github/workflows/tests.yml | 29 ++++++++++--------- 5 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build_native_runtime.yml b/.github/workflows/build_native_runtime.yml index cbe051e680e..c38bc23b8bb 100644 --- a/.github/workflows/build_native_runtime.yml +++ b/.github/workflows/build_native_runtime.yml @@ -12,9 +12,9 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, macos-latest, self-hosted, windows-2019] + os: [ ubuntu-18.04, macos-latest, self-hosted, windows-2019 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive @@ -34,8 +34,9 @@ jobs: mingw-w64-x86_64-make - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: Install build tools (Mac OS) @@ -48,7 +49,7 @@ jobs: - name: Cache ICU build output (Non Windows) id: cache-icu - uses: actions/cache@v2 + uses: actions/cache@v3 if: runner.os == 'Linux' || runner.os == 'macOS' with: path: ~/icu-bin @@ -56,7 +57,7 @@ jobs: - name: Cache ICU build output (Windows) id: cache-icu-windows - uses: actions/cache@v2 + uses: actions/cache@v3 if: runner.os == 'Windows' with: path: D:\msys64\home\runneradmin\icu-bin @@ -126,7 +127,7 @@ jobs: - name: Upload libnativeruntime (Non Windows) if: runner.os == 'Linux' || runner.os == 'macOS' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: ${{env.NATIVERUNTIME_ARTIFACT_FILE}} path: | @@ -134,7 +135,7 @@ jobs: - name: Upload libnativeruntime (Windows) if: runner.os == 'Windows' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: robolectric-nativeruntime-windows-x86_64.dll path: | diff --git a/.github/workflows/check_aggregateDocs.yml b/.github/workflows/check_aggregateDocs.yml index 75364e2327d..2a8fc49e917 100644 --- a/.github/workflows/check_aggregateDocs.yml +++ b/.github/workflows/check_aggregateDocs.yml @@ -12,13 +12,13 @@ jobs: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: recursive - name: Set up JDK - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: 'zulu' # zulu suports complete JDK list java-version: 14 diff --git a/.github/workflows/check_code_formatting.yml b/.github/workflows/check_code_formatting.yml index 05bd8e28d50..05cea9989d3 100644 --- a/.github/workflows/check_code_formatting.yml +++ b/.github/workflows/check_code_formatting.yml @@ -12,13 +12,14 @@ jobs: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up JDK 11.0.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11.0.8 - name: Download google-java-format 1.9 diff --git a/.github/workflows/gradle_wrapper_validation.yml b/.github/workflows/gradle_wrapper_validation.yml index f8296e5a8ab..25f5270270b 100644 --- a/.github/workflows/gradle_wrapper_validation.yml +++ b/.github/workflows/gradle_wrapper_validation.yml @@ -12,5 +12,5 @@ jobs: name: Validation runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 298cd6ba3d8..576ca6601f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.gradle @@ -25,13 +25,14 @@ jobs: ${{ runner.os }}-gradle- - name: Set up JDK 11.0.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11.0.8 - name: Cache ICU build output id: cache-icu - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/icu-bin key: ${{ runner.os }}-${{ runner.arch }}-icu-${{ hashFiles('nativeruntime/external/icu/**') }} @@ -58,13 +59,13 @@ jobs: strategy: fail-fast: false matrix: - api-versions: ['16,17,18', '19,21,22', '23,24,25', '26,27,28', '29,30', '31,32'] + api-versions: [ '16,17,18', '19,21,22', '23,24,25', '26,27,28', '29,30', '31,32' ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | ~/.gradle @@ -75,13 +76,14 @@ jobs: ${{ runner.os }}-gradle- - name: Set up JDK 11.0.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11.0.8 - name: Cache ICU build output id: cache-icu - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/icu-bin key: ${{ runner.os }}-${{ runner.arch }}-icu-${{ hashFiles('nativeruntime/external/icu/**') }} @@ -100,7 +102,7 @@ jobs: -Dorg.gradle.workers.max=2 - name: Upload Test Results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: always() with: name: test_results_${{ matrix.api-versions }} @@ -118,13 +120,14 @@ jobs: api-level: [ 28, 30 ] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - name: Set up JDK 11.0.8 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11.0.8 - name: Determine emulator target @@ -144,7 +147,7 @@ jobs: - name: Upload test results if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: test-results-${{ matrix.api-level }}-${{ steps.determine-target.outputs.TARGET }}-${{ matrix.shard }} path: | From 2b8b04a20a9a880fae9063d8a19f7dfee9dd31ab Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 27 Mar 2022 12:56:33 +0800 Subject: [PATCH 03/10] Use gradle-build-action --- .github/workflows/check_aggregateDocs.yml | 3 ++- .github/workflows/check_code_formatting.yml | 2 ++ .github/workflows/tests.yml | 23 ++++++--------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/check_aggregateDocs.yml b/.github/workflows/check_aggregateDocs.yml index 2a8fc49e917..d7702c2b349 100644 --- a/.github/workflows/check_aggregateDocs.yml +++ b/.github/workflows/check_aggregateDocs.yml @@ -22,7 +22,8 @@ jobs: with: distribution: 'zulu' # zulu suports complete JDK list java-version: 14 - cache: 'gradle' + + - uses: gradle/gradle-build-action@v2 - name: Run aggregateDocs run: SKIP_NATIVERUNTIME_BUILD=true ./gradlew clean aggregateDocs # building the native runtime is not required for checking javadoc diff --git a/.github/workflows/check_code_formatting.yml b/.github/workflows/check_code_formatting.yml index 05cea9989d3..0317a193120 100644 --- a/.github/workflows/check_code_formatting.yml +++ b/.github/workflows/check_code_formatting.yml @@ -22,6 +22,8 @@ jobs: distribution: 'zulu' java-version: 11.0.8 + - uses: gradle/gradle-build-action@v2 + - name: Download google-java-format 1.9 run: | curl -L -o $HOME/google-java-format.jar https://github.com/google/google-java-format/releases/download/v1.15.0/google-java-format-1.15.0-all-deps.jar diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 576ca6601f7..816ef74ae24 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,14 +15,6 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/cache@v3 - with: - path: | - ~/.gradle - ~/.m2 - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - name: Set up JDK 11.0.8 uses: actions/setup-java@v3 @@ -30,6 +22,8 @@ jobs: distribution: 'zulu' java-version: 11.0.8 + - uses: gradle/gradle-build-action@v2 + - name: Cache ICU build output id: cache-icu uses: actions/cache@v3 @@ -65,15 +59,6 @@ jobs: - uses: actions/checkout@v3 with: submodules: recursive - - uses: actions/cache@v3 - with: - path: | - ~/.gradle - ~/.m2 - ~/sqlite - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - name: Set up JDK 11.0.8 uses: actions/setup-java@v3 @@ -81,6 +66,8 @@ jobs: distribution: 'zulu' java-version: 11.0.8 + - uses: gradle/gradle-build-action@v2 + - name: Cache ICU build output id: cache-icu uses: actions/cache@v3 @@ -130,6 +117,8 @@ jobs: distribution: 'zulu' java-version: 11.0.8 + - uses: gradle/gradle-build-action@v2 + - name: Determine emulator target id: determine-target run: | From 85ca8c99cf472c51c83ce881a4c47cabfdd2535a Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 27 Mar 2022 13:01:49 +0800 Subject: [PATCH 04/10] Cache AVD --- .github/workflows/tests.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 816ef74ae24..7ee08c8e8b5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -124,6 +124,25 @@ jobs: run: | TARGET="google_apis" echo "::set-output name=TARGET::$TARGET" + + - name: AVD cache + uses: actions/cache@v3 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ matrix.api-level }} + + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: false + script: echo "Generated AVD snapshot for caching." - name: Run device tests uses: reactivecircus/android-emulator-runner@v2 From b8400541d58e9bd3928a0486c81dd22bb457d50d Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 27 Mar 2022 14:20:18 +0800 Subject: [PATCH 05/10] Set arch to x86_64 --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ee08c8e8b5..a1b723b1507 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -139,6 +139,7 @@ jobs: uses: reactivecircus/android-emulator-runner@v2 with: api-level: ${{ matrix.api-level }} + arch: x86_64 force-avd-creation: false emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: false From 4bd60fd2194f6013dbaac9f94c5ba5e547f4f80e Mon Sep 17 00:00:00 2001 From: utzcoz Date: Wed, 16 Mar 2022 13:59:57 +0800 Subject: [PATCH 06/10] Enable ignored tests again for ThemeTest Signed-off-by: utzcoz --- .../java/android/content/res/ThemeTest.java | 56 ++++++++----------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ThemeTest.java b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ThemeTest.java index 2e48b211ecb..f9f739f14a4 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ThemeTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ThemeTest.java @@ -6,10 +6,9 @@ import android.content.res.Resources.Theme; import android.graphics.Color; import android.util.TypedValue; -import androidx.test.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.annotation.internal.DoNotInstrument; @@ -27,18 +26,18 @@ public class ThemeTest { @Before public void setup() throws Exception { - context = InstrumentationRegistry.getTargetContext(); + context = InstrumentationRegistry.getInstrumentation().getTargetContext(); resources = context.getResources(); } @Test - public void withEmptyTheme_returnsEmptyAttributes() throws Exception { + public void withEmptyTheme_returnsEmptyAttributes() { assertThat(resources.newTheme().obtainStyledAttributes(new int[] {R.attr.string1}).hasValue(0)) .isFalse(); } @Test - public void shouldLookUpStylesFromStyleResId() throws Exception { + public void shouldLookUpStylesFromStyleResId() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); TypedArray a = theme.obtainStyledAttributes(R.style.MyCustomView, R.styleable.CustomView); @@ -48,7 +47,7 @@ public void shouldLookUpStylesFromStyleResId() throws Exception { } @Test - public void shouldApplyStylesFromResourceReference() throws Exception { + public void shouldApplyStylesFromResourceReference() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); TypedArray a = @@ -60,7 +59,7 @@ public void shouldApplyStylesFromResourceReference() throws Exception { } @Test - public void shouldApplyStylesFromAttributeReference() throws Exception { + public void shouldApplyStylesFromAttributeReference() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_ThirdTheme, true); TypedArray a = @@ -72,7 +71,7 @@ public void shouldApplyStylesFromAttributeReference() throws Exception { } @Test - public void shouldGetValuesFromAttributeReference() throws Exception { + public void shouldGetValuesFromAttributeReference() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_ThirdTheme, true); @@ -89,7 +88,7 @@ public void shouldGetValuesFromAttributeReference() throws Exception { } @Test - public void withResolveRefsFalse_shouldResolveValue() throws Exception { + public void withResolveRefsFalse_shouldResolveValue() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); @@ -102,7 +101,7 @@ public void withResolveRefsFalse_shouldResolveValue() throws Exception { } @Test - public void withResolveRefsFalse_shouldNotResolveResource() throws Exception { + public void withResolveRefsFalse_shouldNotResolveResource() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); @@ -115,7 +114,7 @@ public void withResolveRefsFalse_shouldNotResolveResource() throws Exception { } @Test - public void withResolveRefsTrue_shouldResolveResource() throws Exception { + public void withResolveRefsTrue_shouldResolveResource() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); @@ -129,7 +128,7 @@ public void withResolveRefsTrue_shouldResolveResource() throws Exception { } @Test - public void failToResolveCircularReference() throws Exception { + public void failToResolveCircularReference() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); @@ -140,7 +139,7 @@ public void failToResolveCircularReference() throws Exception { } @Test - public void canResolveAttrReferenceToDifferentPackage() throws Exception { + public void canResolveAttrReferenceToDifferentPackage() { Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); @@ -153,8 +152,7 @@ public void canResolveAttrReferenceToDifferentPackage() throws Exception { } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() throws Exception { + public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric_ImplicitChild, true); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -164,15 +162,14 @@ public void forStylesWithImplicitParents_shouldInheritValuesNotDefinedInChild() } @Test - public void whenAThemeHasExplicitlyEmptyParentAttr_shouldHaveNoParent() throws Exception { + public void whenAThemeHasExplicitlyEmptyParentAttr_shouldHaveNoParent() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric_EmptyParent, true); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).hasValue(0)).isFalse(); } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void shouldApplyParentStylesFromAttrs() throws Exception { + public void shouldApplyParentStylesFromAttrs() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_AnotherTheme, true); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -182,8 +179,7 @@ public void shouldApplyParentStylesFromAttrs() throws Exception { } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void setTo_shouldCopyAllAttributesToEmptyTheme() throws Exception { + public void setTo_shouldCopyAllAttributesToEmptyTheme() { Resources.Theme theme1 = resources.newTheme(); theme1.applyStyle(R.style.Theme_Robolectric, false); assertThat(theme1.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -197,8 +193,7 @@ public void setTo_shouldCopyAllAttributesToEmptyTheme() throws Exception { } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void setTo_whenDestThemeIsModified_sourceThemeShouldNotMutate() throws Exception { + public void setTo_whenDestThemeIsModified_sourceThemeShouldNotMutate() { Resources.Theme sourceTheme = resources.newTheme(); sourceTheme.applyStyle(R.style.Theme_Robolectric, false); assertThat(sourceTheme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -213,8 +208,7 @@ public void setTo_whenDestThemeIsModified_sourceThemeShouldNotMutate() throws Ex } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void setTo_whenSourceThemeIsModified_destThemeShouldNotMutate() throws Exception { + public void setTo_whenSourceThemeIsModified_destThemeShouldNotMutate() { Resources.Theme sourceTheme = resources.newTheme(); sourceTheme.applyStyle(R.style.Theme_Robolectric, false); assertThat(sourceTheme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -229,9 +223,7 @@ public void setTo_whenSourceThemeIsModified_destThemeShouldNotMutate() throws Ex } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() - throws Exception { + public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttributeValues() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric, false); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -245,9 +237,7 @@ public void applyStyle_withForceFalse_shouldApplyButNotOverwriteExistingAttribut } @Test - @Ignore("todo: incorrect behavior on robolectric vs framework?") - public void applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues() - throws Exception { + public void applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeValues() { Resources.Theme theme = resources.newTheme(); theme.applyStyle(R.style.Theme_Robolectric, false); assertThat(theme.obtainStyledAttributes(new int[] {R.attr.string1}).getString(0)) @@ -264,7 +254,7 @@ public void applyStyle_withForceTrue_shouldApplyAndOverwriteExistingAttributeVal } @Test - public void shouldFindInheritedAndroidAttributeInTheme() throws Exception { + public void shouldFindInheritedAndroidAttributeInTheme() { context.setTheme(R.style.Theme_AnotherTheme); Resources.Theme theme1 = context.getTheme(); @@ -275,7 +265,7 @@ public void shouldFindInheritedAndroidAttributeInTheme() throws Exception { } @Test - public void themesShouldBeApplyableAcrossResources() throws Exception { + public void themesShouldBeApplyableAcrossResources() { Resources.Theme themeFromSystem = Resources.getSystem().newTheme(); themeFromSystem.applyStyle(android.R.style.Theme_Light, true); @@ -307,7 +297,7 @@ public void themesShouldBeApplyableAcrossResources() throws Exception { } @Test - public void styleResolutionShouldIgnoreThemes() throws Exception { + public void styleResolutionShouldIgnoreThemes() { Resources.Theme themeFromSystem = resources.newTheme(); themeFromSystem.applyStyle(android.R.style.Theme_DeviceDefault, true); themeFromSystem.applyStyle(R.style.ThemeWithSelfReferencingTextAttr, true); From 40af7422e479ee033646dd7557d5ce4ff4702025 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Thu, 17 Mar 2022 21:09:11 +0800 Subject: [PATCH 07/10] Remove unused Exception from ResourcesTest Signed-off-by: utzcoz --- .../sharedTest/java/android/content/res/ResourcesTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java index 6a06d5e90d6..b6508cd5946 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java @@ -1048,8 +1048,7 @@ public void whenPackageIsUnknown_getResourceIdentifier_shouldReturnZero() { @Ignore( "currently ids are always automatically assigned a value; to fix this we'd need to check " + "layouts for +@id/___, which is expensive") - public void whenCalledForIdWithNameNotInRClassOrXml_getResourceIdentifier_shouldReturnZero() - throws Exception { + public void whenCalledForIdWithNameNotInRClassOrXml_getResourceIdentifier_shouldReturnZero() { assertThat( resources.getIdentifier( "org.robolectric:id/idThatDoesntExistAnywhere", "other", "other")) @@ -1058,8 +1057,7 @@ public void whenCalledForIdWithNameNotInRClassOrXml_getResourceIdentifier_should @Test public void - whenIdIsAbsentInXmlButPresentInRClass_getResourceIdentifier_shouldReturnIdFromRClass_probablyBecauseItWasDeclaredInALayout() - throws Exception { + whenIdIsAbsentInXmlButPresentInRClass_getResourceIdentifier_shouldReturnIdFromRClass_probablyBecauseItWasDeclaredInALayout() { assertThat( resources.getIdentifier("id_declared_in_layout", "id", context.getPackageName())) .isEqualTo(R.id.id_declared_in_layout); From 61fb4512ad239d40fb1eb4c2312541eec94ff2d9 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Thu, 17 Mar 2022 21:22:44 +0800 Subject: [PATCH 08/10] Migrate InstrumentationRegistry to platfom package for BitmapFactoryTest Signed-off-by: utzcoz --- .../java/android/graphics/BitmapFactoryTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/integration_tests/ctesque/src/sharedTest/java/android/graphics/BitmapFactoryTest.java b/integration_tests/ctesque/src/sharedTest/java/android/graphics/BitmapFactoryTest.java index 3e1dc4fcaad..479209f2581 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/graphics/BitmapFactoryTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/graphics/BitmapFactoryTest.java @@ -1,6 +1,5 @@ package android.graphics; -import static androidx.test.InstrumentationRegistry.getTargetContext; import static com.google.common.truth.Truth.assertThat; import android.content.res.Resources; @@ -8,10 +7,10 @@ import android.graphics.BitmapFactory.Options; import android.os.Build; import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import com.google.common.truth.TruthJUnit; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import org.junit.Before; @@ -33,7 +32,7 @@ public class BitmapFactoryTest { @Before public void setUp() { - resources = getTargetContext().getResources(); + resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources(); } @Test @@ -88,7 +87,7 @@ private byte[] obtainArray() { * can be enabled for Robolectric. */ @Test - public void decodeStream_options_setsOutWidthToMinusOne() throws IOException { + public void decodeStream_options_setsOutWidthToMinusOne() { TruthJUnit.assume().that(Build.FINGERPRINT).isNotEqualTo("robolectric"); byte[] invalidBitmapPixels = "invalid bitmap pixels".getBytes(Charset.defaultCharset()); ByteArrayInputStream inputStream = new ByteArrayInputStream(invalidBitmapPixels); From 0001a618b0f10fb9bba78f5c3323a013c9866018 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Thu, 17 Mar 2022 21:48:18 +0800 Subject: [PATCH 09/10] Enable ignored tests for MotionEventTest Signed-off-by: utzcoz --- .../src/sharedTest/java/android/view/MotionEventTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration_tests/ctesque/src/sharedTest/java/android/view/MotionEventTest.java b/integration_tests/ctesque/src/sharedTest/java/android/view/MotionEventTest.java index 94ca3d3574c..c34d6c982c8 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/view/MotionEventTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/view/MotionEventTest.java @@ -22,7 +22,6 @@ import com.google.common.truth.Truth; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.annotation.internal.DoNotInstrument; @@ -322,7 +321,6 @@ public void testReadFromParcelWithInvalidPointerCountSize() { } @Test - @Ignore // doesn't actually fail when expected on emulator API 23 public void testReadFromParcelWithInvalidSampleSize() { Parcel parcel = Parcel.obtain(); motionEvent2.writeToParcel(parcel, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); From 2ca91152ffd701f0398f522d63769b2c1b814fe1 Mon Sep 17 00:00:00 2001 From: utzcoz Date: Thu, 17 Mar 2022 22:47:52 +0800 Subject: [PATCH 10/10] Remove unused Exception from ActivityTest Signed-off-by: utzcoz --- .../sharedTest/java/android/app/ActivityTest.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/integration_tests/ctesque/src/sharedTest/java/android/app/ActivityTest.java b/integration_tests/ctesque/src/sharedTest/java/android/app/ActivityTest.java index f6fa505a2f1..4d878703218 100644 --- a/integration_tests/ctesque/src/sharedTest/java/android/app/ActivityTest.java +++ b/integration_tests/ctesque/src/sharedTest/java/android/app/ActivityTest.java @@ -33,8 +33,7 @@ public void setUp() throws Exception { } @Test - public void whenSetOnActivityInManifest_activityGetsThemeFromActivityInManifest() - throws Exception { + public void whenSetOnActivityInManifest_activityGetsThemeFromActivityInManifest() { Activity activity = activityWithAnotherThemeRule.launchActivity(null); Button theButton = activity.findViewById(R.id.button); ColorDrawable background = (ColorDrawable) theButton.getBackground(); @@ -42,8 +41,8 @@ public void whenSetOnActivityInManifest_activityGetsThemeFromActivityInManifest( } @Test - public void whenExplicitlySetOnActivity_afterSetContentView_activityGetsThemeFromActivityInManifest() - throws Exception { + public void + whenExplicitlySetOnActivity_afterSetContentView_activityGetsThemeFromActivityInManifest() { Activity activity = activityWithAnotherThemeRule.launchActivity(null); activity.setTheme(R.style.Theme_Robolectric); Button theButton = activity.findViewById(R.id.button); @@ -52,8 +51,7 @@ public void whenExplicitlySetOnActivity_afterSetContentView_activityGetsThemeFro } @Test - public void whenExplicitlySetOnActivity_beforeSetContentView_activityUsesNewTheme() - throws Exception { + public void whenExplicitlySetOnActivity_beforeSetContentView_activityUsesNewTheme() { ActivityWithAnotherTheme.setThemeBeforeContentView = R.style.Theme_Robolectric; Activity activity = activityWithAnotherThemeRule.launchActivity(null); Button theButton = activity.findViewById(R.id.button); @@ -62,12 +60,10 @@ public void whenExplicitlySetOnActivity_beforeSetContentView_activityUsesNewThem } @Test - public void whenNotSetOnActivityInManifest_activityGetsThemeFromApplicationInManifest() - throws Exception { + public void whenNotSetOnActivityInManifest_activityGetsThemeFromApplicationInManifest() { Activity activity = activityWithoutThemeRule.launchActivity(null); Button theButton = activity.findViewById(R.id.button); ColorDrawable background = (ColorDrawable) theButton.getBackground(); assertThat(background.getColor()).isEqualTo(0xff00ff00); } - }