Skip to content
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

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

JohannesPtaszyk
Copy link
Contributor

@JohannesPtaszyk JohannesPtaszyk commented Nov 17, 2024

  • Bumped version of robolectric to 4.14
  • Ran tests

Closes #98

Summary by CodeRabbit

  • New Features

    • Updated the Robolectric library version to enhance testing capabilities.
  • Bug Fixes

    • Improved URL handling for better robustness against malformed URLs.
    • Enhanced error logging to provide clearer messages.
  • Refactor

    • Removed unnecessary parameters from constructors in sandbox classes for streamlined functionality.
    • Updated parameter types for improved specificity in sandbox methods and data structures.
  • Tests

    • Adjusted test cases to reflect changes in parameter types and ensure accurate sandbox behavior verification.

Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

Walkthrough

The 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 downloadAarDepsPlugin task in the build.gradle file, enhancing URL handling and error logging. Changes in the robolectric-extension module include adjustments to constructor parameters and method signatures to improve type specificity, particularly regarding the resourcesMode parameter.

Changes

File Path Change Summary
buildSrc/build.gradle Updated URL handling in downloadAarDepsPlugin task and improved error logging.
gradle/libs.versions.toml Updated Robolectric version from 4.13 to 4.14.
robolectric-extension/src/main/kotlin/.../JUnit5RobolectricAndroidSandbox.kt Removed apkLoader parameter and changed resourcesMode type in constructor.
robolectric-extension/src/main/kotlin/.../JUnit5RobolectricSandboxBuilder.kt Removed apkLoader parameter, changed resourcesMode type in constructor and build method.
robolectric-extension/src/main/kotlin/.../JUnit5RobolectricSandboxManager.kt Changed resourcesMode type in getAndroidSandbox method and SandboxKey data class.
robolectric-extension/src/test/kotlin/.../JUnit5RobolectricSandboxBuilderTest.kt Updated resourcesMode variable type in tests and modified import statement.

Assessment against linked issues

Objective Addressed Explanation
Bump Robolectric to 4.14 (#98)

Possibly related PRs

  • build: Change java version to 17 for robolectric-extension tests #83: The changes in the main PR regarding the buildSrc/build.gradle file and the downloadAarDepsPlugin task may relate to the updates in the build.gradle file for the robolectric-extension project, as both involve modifications to Gradle build configurations and task handling.

Poem

In the garden of code, we hop and play,
Robolectric's new version brightens the day.
With URLs handled, errors now clear,
Our tests will run smoothly, there's nothing to fear!
So let’s leap with joy, and code with delight,
For changes are here, making everything right! 🐇✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 changes

Since this update affects how Android resources are handled in tests (via the new ResourcesMode.Mode), consider:

  1. Documenting any behavioral changes in test execution
  2. Updating test guidelines if resource handling strategies have changed
  3. 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 changes

The changes properly adapt the sandbox management to Robolectric 4.14's more specific type system by using ResourcesMode.Mode instead of ResourcesMode. 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 upgrade

While 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 2

Length 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 kotlin

Length of output: 2012


Remove @ignore annotation as it's preventing critical sandbox tests from running

The @Ignore annotation on JUnit5RobolectricSandboxBuilderTest appears to be unnecessary as:

  1. This is the only sandbox-related test class that is fully ignored
  2. The test methods verify critical sandbox behavior that should be validated with the Robolectric 4.14 upgrade
  3. The test class was added recently (in a Kotlin update commit) with the @Ignore annotation without any documented reason
  4. 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 annotation

The 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 --all

Length 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

📥 Commits

Reviewing files that changed from the base of the PR and between 207d2d9 and d660ddf.

📒 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:

  1. All usages of ResourcesMode have been updated to use ResourcesMode.Mode
  2. 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

buildSrc/build.gradle Show resolved Hide resolved
@warnyul warnyul self-requested a review November 18, 2024 13:52
@warnyul warnyul changed the title Bump robolectric to 4.14 chore: Bump robolectric to 4.14 (#98) Nov 18, 2024
@warnyul warnyul merged commit 2ab5bf8 into apter-tech:main Nov 18, 2024
5 of 7 checks passed
@JohannesPtaszyk JohannesPtaszyk deleted the robolectric_4.14 branch November 18, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bump Robolectric to 4.14
2 participants