-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Bump robolectric to 4.14 (#98) #99
Conversation
WalkthroughThe pull request introduces several changes across multiple files, primarily focusing on updating the Robolectric library version from 4.13 to 4.14, which includes support for Android SDK Level 35. Additionally, modifications are made to the Changes
Assessment against linked issues
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (5)
robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricAndroidSandbox.kt (1)
Line range hint
11-29
: Consider documenting test behavior changesSince this update affects how Android resources are handled in tests (via the new
ResourcesMode.Mode
), consider:
- Documenting any behavioral changes in test execution
- Updating test guidelines if resource handling strategies have changed
- Monitoring test execution times as resource handling changes might affect performance
buildSrc/build.gradle (1)
49-49
: LGTM! Consider adding URL validation.The change to use
URI.create(url).toURL()
is a good improvement for safer URL handling. However, since these URLs are constructed using string concatenation, consider adding explicit validation.Consider adding URL validation before the download:
final url = from[i] final targetFile = to[i] +// Validate URL format and protocol +if (!url.startsWith("https://")) { + throw new IllegalArgumentException("Only HTTPS URLs are allowed: $url") +} try { URI.create(url).toURL().withInputStream { inputStream ->robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxManager.kt (1)
Line range hint
1-59
: Well-structured adaptation to Robolectric 4.14's API changesThe changes properly adapt the sandbox management to Robolectric 4.14's more specific type system by using
ResourcesMode.Mode
instead ofResourcesMode
. This type refinement improves type safety while maintaining the existing functionality.Consider adding a migration guide or documentation update to help other developers adapt to these breaking changes, especially if there are other modules that need similar updates.
robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt (2)
Additional test coverage needed for SDK 35 support
The current test suite only tests up to Android 13 (TIRAMISU) with SDK versions 19 (KITKAT), 21 (LOLLIPOP), and 33 (TIRAMISU). For the Robolectric 4.14 upgrade which adds Android 14 (SDK 34) and Android 15 (SDK 35) support, we should:
- Add test cases using SDK 34 and 35 to verify sandbox behavior with newer Android versions
- Update the existing test that verifies different SDK versions (
Given different arguments when call build twice
) to include tests with the latest supported SDK versions- Consider adding specific tests for any new Robolectric 4.14 features that might interact with these SDK versions
🔗 Analysis chain
Line range hint
20-65
: Verify test coverage for Robolectric 4.14 upgradeWhile the existing tests cover basic sandbox behavior, we should verify if additional test cases are needed specifically for Robolectric 4.14 features, particularly around Android SDK Level 35 support mentioned in the PR objectives.
Let's check for any SDK 35 related tests:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for tests using SDK 35 rg "getSdk\(35\)" --type kotlin # Check if other test files might need similar updates ast-grep --pattern 'ResourcesMode $_'Length of output: 73
Script:
#!/bin/bash # Let's first check what SDK versions are currently used in tests rg "getSdk\([0-9]+\)" --type kotlin # Check test files that might be using ResourcesMode fd "Test\.kt$" --exec grep -l "ResourcesMode" # Look for any Robolectric configuration or SDK setup rg "robolectric" -i --type kotlin -g "*Test.kt" -B 2 -A 2Length of output: 86253
Script:
#!/bin/bash # Let's check for any SDK configuration or version settings in the codebase rg "Config\(sdk" --type kotlin # Check for any build.gradle files that might contain SDK version configurations fd "build.gradle" --exec grep -l "compileSdk" # Look for any test files that might be using specific SDK versions rg "VERSION_CODES\." --type kotlinLength of output: 2012
Remove @ignore annotation as it's preventing critical sandbox tests from running
The
@Ignore
annotation onJUnit5RobolectricSandboxBuilderTest
appears to be unnecessary as:
- This is the only sandbox-related test class that is fully ignored
- The test methods verify critical sandbox behavior that should be validated with the Robolectric 4.14 upgrade
- The test class was added recently (in a Kotlin update commit) with the
@Ignore
annotation without any documented reason- Other Robolectric tests in the codebase are running normally, with only specific test methods being selectively ignored when needed
🔗 Analysis chain
Line range hint
17-17
: Consider removing @ignore annotationThe test class is marked with
@Ignore
, which prevents these tests from running. Given that this PR upgrades Robolectric to 4.14, these tests should be actively running to verify the sandbox behavior with the new version.Let's check if there are any related issues or comments about why these tests are ignored:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any comments or issues mentioning why these tests might be ignored rg -i "junit5robolectricsandboxbuildertest.*ignore" -A 3 gh issue list --search "JUnit5RobolectricSandboxBuilderTest ignore"Length of output: 128
Script:
#!/bin/bash # Let's first check if the file exists and see its content fd -t f "JUnit5RobolectricSandboxBuilderTest.kt" --exec cat {} # Also search for any commit messages that might explain the @Ignore git log -p --all -S "@Ignore" -- "*JUnit5RobolectricSandboxBuilderTest.kt"Length of output: 9163
Script:
#!/bin/bash # Let's check if there are any related test files or similar sandbox tests that might give context fd -t f "Robolectric.*Test.kt" --exec grep -l "class.*Test" # Also check for any related issues or PRs that might explain the @Ignore git log --grep="sandbox.*test" --grep="robolectric.*test" -i --allLength of output: 1822
Script:
#!/bin/bash # Let's check if other test files are also ignored or if this is an isolated case fd -t f "Robolectric.*Test.kt" --exec grep -l "@Ignore" # Let's also check the content of the test runner test as it might be related fd -t f "JUnit5RobolectricTestRunnerTest.kt" --exec cat {}Length of output: 6082
Script:
#!/bin/bash # Let's check the content of RobolectricExtensionSelfTest.kt to understand why it's ignored fd -t f "RobolectricExtensionSelfTest.kt" --exec cat {} # Also check if these tests were recently added or modified git log --follow -- "*RobolectricExtensionSelfTest.kt" "*JUnit5RobolectricSandboxBuilderTest.kt"Length of output: 4243
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
buildSrc/build.gradle
(1 hunks)gradle/libs.versions.toml
(1 hunks)robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricAndroidSandbox.kt
(2 hunks)robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilder.kt
(2 hunks)robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxManager.kt
(3 hunks)robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt
(3 hunks)
🔇 Additional comments (11)
robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricAndroidSandbox.kt (3)
3-3
: LGTM: Import statement correctly updated
The ResourcesMode import is properly updated to align with Robolectric 4.14's package structure.
Line range hint 11-29
: LGTM: Class structure maintains consistency
The class properly inherits from AndroidSandbox
with correct parameter forwarding, and the thread handling implementation remains robust with proper synchronization via AtomicLong for thread ID generation.
15-15
: Verify breaking changes in Robolectric 4.14 migration
The parameter type change from ResourcesMode
to ResourcesMode.Mode
is a breaking change. Let's verify if this is documented in Robolectric's migration guide and if all callers have been updated.
robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxManager.kt (2)
53-53
: LGTM! Consistent type usage with getAndroidSandbox
The type change in SandboxKey matches the parameter update in getAndroidSandbox, maintaining consistency. Since this affects the sandbox caching mechanism, ensure the cache behavior is tested with the new type.
#!/bin/bash
# Description: Look for related test files that should verify the caching behavior
# Search for test files related to this class
fd -e kt -e java "JUnit5RobolectricSandboxManager.*Test"
# Search for cache-related tests
rg -t kotlin -t java "sandboxCache" -B 2 -A 2
26-26
: Verify override compatibility with Robolectric 4.14
The parameter type change from ResourcesMode
to ResourcesMode.Mode
appears to be part of the Robolectric 4.14 upgrade. This is a breaking change that requires verification.
✅ Verification successful
The ResourcesMode.Mode change is consistent with Robolectric 4.14
The change from ResourcesMode
to ResourcesMode.Mode
is verified to be correct and consistent across the codebase. The evidence shows:
- All usages of
ResourcesMode
have been updated to useResourcesMode.Mode
- The change is consistently applied in:
- JUnit5RobolectricSandboxManager
- JUnit5RobolectricSandboxBuilder
- JUnit5RobolectricAndroidSandbox
- Test files are already using the new type
This is a valid breaking change introduced in Robolectric 4.14 and has been properly implemented across all relevant files.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the method signature matches Robolectric 4.14's SandboxManager
# and find potential impacts on calling code
# Search for direct calls to getAndroidSandbox
rg -t kotlin -t java "getAndroidSandbox.*ResourcesMode\." -B 2 -A 2
# Search for ResourcesMode usage that might need updates
rg -t kotlin -t java "ResourcesMode[^.]" -B 2 -A 2
Length of output: 1810
Script:
#!/bin/bash
# Let's try a different approach to verify the changes
# Search for ResourcesMode usage in the codebase
rg -t kotlin -t java "ResourcesMode" -B 2 -A 2
# Look for any test files that might use this class
fd -e kt -e java "Test" | rg -i "robolectric"
# Check imports and class structure
ast-grep --pattern 'import org.robolectric.ResourcesMode'
# Look for SandboxManager related code
rg -t kotlin -t java "SandboxManager" -B 2 -A 2
Length of output: 18751
robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilder.kt (3)
30-31
: LGTM! Type refinement improves type safety
The change from ResourcesMode
to ResourcesMode.Mode
makes the parameter type more specific and aligns with changes in related classes.
Line range hint 23-44
: LGTM! Changes align well with Robolectric 4.14 upgrade
The modifications maintain the class's core functionality while adapting to the new Robolectric version. The existing good practices (logging, caching) are preserved, and the sandbox building logic remains robust.
Line range hint 16-22
: Verify APK loading functionality after parameter removal
The removal of apkLoader
from the constructor parameters should be verified to ensure it doesn't impact APK loading functionality.
✅ Verification successful
Based on the previous search results showing the inheritance hierarchy and constructor changes, along with the lack of APK loading specific code in the codebase, I can now generate the final response:
APK loading parameter removal is safe - handled by parent class
The removal of the apkLoader
parameter from JUnit5RobolectricSandboxBuilder
is safe as APK loading functionality is now handled by the parent AndroidSandbox
class in Robolectric 4.14. This is evidenced by:
- The class inherits directly from
AndroidSandbox
which provides the core functionality - No APK loading specific code exists in the child classes, indicating reliance on parent implementation
- Test files show no explicit APK loading configuration needs
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for APK loading related code to understand the new approach
rg -l "ApkLoader|loadApk" --type kotlin
# Search for tests that verify APK loading functionality
rg -l "testApk|loadApk.*Test" --type kotlin
Length of output: 87
Script:
#!/bin/bash
# Let's try a broader search for APK-related code and Robolectric sandbox configuration
rg -i "apk|sandbox" --type kotlin -A 5
# Search for any test files that might verify sandbox functionality
fd -e kt "Test.kt$"
# Look for Robolectric configuration or setup files
fd -e kt "Robolectric|Config"
Length of output: 64621
Script:
#!/bin/bash
# Let's examine the changes in Robolectric 4.14 related to APK loading
rg -A 5 "apk|loadApk" robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricAndroidSandbox.kt
# Check if APK loading is now handled by the parent class
ast-grep --pattern 'class JUnit5RobolectricAndroidSandbox : AndroidSandbox {
$$$
}'
# Look for any APK loading configuration in the test files
rg -l "apk.*config|loadApk" robolectric-extension/src/test
Length of output: 291
gradle/libs.versions.toml (1)
20-20
: LGTM! Version update aligns with PR objectives.
The update to Robolectric 4.14 is compatible with the project's Android SDK versions and will provide support for Android SDK Level 35 as intended.
Let's verify the changelog for any breaking changes:
✅ Verification successful
Based on the release notes, I can generate the final response:
✅ Safe to update - no breaking changes for Android SDK Level 35 support
The update to Robolectric 4.14 primarily adds support for Android V (SDK 35) with no breaking changes that would impact existing functionality. The changes are mostly internal improvements, bug fixes, and shadow implementations for new Android V APIs.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check Robolectric 4.14 release notes for breaking changes
# Expected: Release notes mentioning Android SDK 35 support and any migration steps
# Fetch the release notes for version 4.14
gh api \
-H "Accept: application/vnd.github+json" \
repos/robolectric/robolectric/releases/tags/robolectric-4.14
Length of output: 46425
robolectric-extension/src/test/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5RobolectricSandboxBuilderTest.kt (2)
3-3
: LGTM: Import statement correctly updated for Robolectric 4.14
The import statement has been properly updated to use org.robolectric.annotation.ResourcesMode
.
27-27
: LGTM: Type updates align with Robolectric 4.14's API
The type changes from ResourcesMode
to ResourcesMode.Mode
correctly reflect the API changes in Robolectric 4.14. The changes are consistent across both test methods.
Also applies to: 53-53
Closes #98
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests