-
Notifications
You must be signed in to change notification settings - Fork 78
task(SDK-4674): Replace Mockito with Mockk in Kotlin tests #805
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
Conversation
""" WalkthroughThis update migrates all test code from the Mockito mocking framework to MockK across the codebase, including both core and HMS modules, as well as shared test utilities. All mocking, verification, static mocking, and argument capturing are now handled by MockK. Corresponding build files and dependency versions were updated to remove Mockito and use MockK instead. Additionally, the geofence module test suite was rewritten from Java to Kotlin with MockK, including new test classes and utilities replacing the previous Java Mockito-based tests. Changes
Sequence Diagram(s)sequenceDiagram
participant TestCase
participant MockK
participant SystemUnderTest
TestCase->>MockK: Create mocks/spies (mockk, spyk)
TestCase->>MockK: Stub methods (every { ... } returns ...)
TestCase->>SystemUnderTest: Invoke method under test
SystemUnderTest->>MockK: Interact with mocked dependencies
TestCase->>MockK: Verify interactions (verify { ... })
TestCase->>MockK: Clear mocks after test (clearAllMocks)
This diagram represents the new, unified test flow using MockK for all mocking, stubbing, and verification in the test suite. Possibly related PRs
Suggested labels
Suggested reviewers
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
Code Coverage Debug
|
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: 0
🧹 Nitpick comments (1)
clevertap-core/src/test/java/com/clevertap/android/sdk/EventQueueManagerTest.kt (1)
1167-1174
: Excellent refactoring with helper methodThe
withMockExecutors
helper method is a great addition that encapsulates the repeated pattern of mockingCTExecutorFactory.executors
. This improves code readability and maintainability by eliminating duplication throughout the test class.As a minor improvement, consider documenting this helper method with a KDoc comment to clearly explain its purpose for future developers.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (53)
clevertap-core/build.gradle
(0 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/ActivityLifeCycleManagerTest.kt
(4 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/ActivityLifecycleCallbackTest.kt
(1 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/ApplicationTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/CTWebInterfaceTest.kt
(9 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/CTXtensionsTest.kt
(10 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/CallbackManagerTest.kt
(3 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/CleverTapAPITest.kt
(20 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/CleverTapFactoryTest.kt
(4 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/EventQueueManagerTest.kt
(25 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/LocalDataStoreTest.kt
(9 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/LocationManagerTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/MockCoreState.kt
(0 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/SessionManagerTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/StorageHelperTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/db/DBManagerTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/displayunits/CTDisplayUnitControllerTest.kt
(3 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/featureFlags/CTFeatureFlagsControllerTest.kt
(7 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/ImpressionManagerTest.kt
(19 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/InAppQueueTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/TriggerManagerTest.kt
(3 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/evaluation/LimitsMatcherTest.kt
(1 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inbox/CTInboxControllerTest.kt
(9 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inbox/CTInboxListViewFragmentTest.kt
(10 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/leanplum/LeanplumCtTest.kt
(13 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/login/ConfigurableIdentityRepoTest.kt
(7 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/login/LoginControllerTest.kt
(8 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/network/NetworkManagerTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiTestProvider.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiWrapperTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/CTProductConfigControllerTest.kt
(6 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/DefaultXmlParserTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/ProductConfigSettingsTest.kt
(6 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/CTFcmMessageHandlerTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmMessageListenerServiceTest.kt
(1 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmNotificationBundleManipulationTest.kt
(6 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmPushProviderTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmSdkHandlerImplTest.kt
(1 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/task/CTExecutorFactoryTest.kt
(1 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/task/IOExecutorTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/task/MainThreadExecutorTest.kt
(2 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/task/PostAsyncSafelyExecutorTest.kt
(7 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/validation/ValidatorTest.kt
(3 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/variables/ParserTest.kt
(4 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/variables/VarCacheTest.kt
(1 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HmsHandlerTest.kt
(1 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HmsMessageHandlerTest.kt
(6 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HmsMessageServiceTest.kt
(2 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HmsPushProviderTest.kt
(2 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HuaweiNotificationParserTest.kt
(4 hunks)gradle/libs.versions.toml
(1 hunks)test_shared/build.gradle
(1 hunks)test_shared/src/main/java/com/clevertap/android/shared/test/BaseTestCase.kt
(4 hunks)
💤 Files with no reviewable changes (2)
- clevertap-core/src/test/java/com/clevertap/android/sdk/MockCoreState.kt
- clevertap-core/build.gradle
🧰 Additional context used
🧬 Code Graph Analysis (1)
clevertap-core/src/test/java/com/clevertap/android/sdk/inbox/CTInboxControllerTest.kt (1)
clevertap-core/src/test/java/com/clevertap/android/sdk/db/DBAdapterTest.kt (1)
getCtMsgDao
(607-630)
🪛 detekt (1.23.8)
clevertap-core/src/test/java/com/clevertap/android/sdk/CallbackManagerTest.kt
[warning] 176-176: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
[warning] 177-177: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
[warning] 221-221: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
[warning] 222-222: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
🔇 Additional comments (231)
test_shared/build.gradle (1)
50-50
: Dependency updated as part of MockK migration.The change adds MockK as an API dependency, replacing the previous Mockito dependency. This aligns with the PR objective to migrate from Mockito to MockK in Kotlin tests.
gradle/libs.versions.toml (1)
49-49
: MockK version added to versions section.The MockK version 1.14.2 has been added to the versions section of the toml file. This is a relatively recent version of MockK that provides good Kotlin compatibility.
clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/TriggerManagerTest.kt (2)
7-7
: Import MockK library.MockK import added as part of the migration from Mockito to MockK.
24-24
: Replace Mockito mock with MockK.The deviceInfo mock is now instantiated using MockK's
mockk(relaxed = true)
instead of Mockito's@Mock
annotation. Therelaxed = true
parameter ensures that the mock will not throw exceptions for unexpected calls, similar to Mockito's lenient behavior.clevertap-core/src/test/java/com/clevertap/android/sdk/variables/VarCacheTest.kt (1)
47-48
: Override base class cleanUp method.The standalone
@After
annotated method has been changed to override the base class'scleanUp()
method and callsuper.cleanUp()
first. This ensures proper cleanup hierarchies are maintained, with the base class cleanup (which likely clears MockK mocks) performed before this class's specific cleanup logic.clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiTestProvider.kt (1)
7-7
: LGTM! Successful migration to MockK.The change from Mockito to MockK is correctly implemented:
- Proper import of the MockK library
- Appropriate use of
mockk(relaxed = true)
to create a mock logger objectThe relaxed parameter ensures that any non-mocked methods will return default values rather than throwing exceptions, which maintains test stability.
Also applies to: 37-37
clevertap-hms/src/test/java/com/clevertap/android/hms/HuaweiNotificationParserTest.kt (1)
8-9
: Mockito to MockK migration implemented correctly.The changes follow MockK best practices:
- Proper imports for MockK classes
- Changed mock creation syntax from
mock(RemoteMessage::class.java)
tomockk<RemoteMessage>(relaxed = true)
- Updated stubbing syntax from Mockito's
when(...).thenReturn(...)
to MockK'severy { ... } returns ...
These changes maintain the same test behavior while modernizing to the new mocking framework.
Also applies to: 26-26, 31-31, 40-40, 52-52
clevertap-core/src/test/java/com/clevertap/android/sdk/CTXtensionsTest.kt (3)
9-11
: Static mocking correctly migrated to MockK.The migration successfully implements MockK's static mocking approach:
- Added proper imports for MockK functionality
- Replaced Mockito's static mocking with MockK's
mockkStatic(ManifestInfo::class) { ... }
pattern- Correctly implemented mocking of the
ManifestInfo.getInstance()
methodMockK's approach to static mocking is different from Mockito's, requiring a lambda block to define the scope, which is correctly implemented here.
Also applies to: 126-131
146-151
: Consistent static mocking implementation throughout the test class.The static mocking pattern has been consistently applied across all test cases that require mocking of
ManifestInfo
. The migration maintains the same test behavior while modernizing to MockK's syntax.Each test case now uses the scoped approach with
mockkStatic
followed by appropriate stubbing withevery { ... } returns ...
, which is the recommended pattern for MockK.Also applies to: 161-166, 182-187, 196-201, 211-216, 232-237, 247-252, 268-274
268-282
: NotificationManager mocking properly implemented with MockK.The mock for
NotificationManager
is correctly configured withrelaxed = true
, and the stubbing of the exception-throwing behavior is properly implemented using MockK's syntax:every { nm.getNotificationChannel("ManifestChannelId") } throws RuntimeException()This ensures the exception test case behaves the same as before.
clevertap-core/src/test/java/com/clevertap/android/sdk/db/DBManagerTest.kt (3)
8-9
: Spy creation successfully migrated to MockK.The changes correctly implement MockK's spy mechanism:
- Updated imports from Mockito to MockK equivalents
- Changed spy creation from
spy(dbManager)
tospyk(dbManager)
MockK's
spyk
function creates a partial mock that allows real method calls while still enabling stubbing and verification.Also applies to: 33-33
101-108
: Method verification syntax updated to MockK's style.The method verification has been correctly migrated from Mockito's approach to MockK's:
- Changed from
verify(dbManagerSpy).methodName(args)
toverify(exactly = 1) { dbManagerSpy.methodName(args) }
- Added explicit
exactly = 1
to specify the expected number of invocationsThis ensures the test continues to verify that methods are called exactly once, maintaining the same test behavior.
Also applies to: 234-240
243-246
: Local spy creation and verification correctly implemented.The local spy creation within a test method has been properly updated to use MockK:
- Changed from
spy(dbManager)
tospyk(dbManager)
- Updated verification syntax to use MockK's pattern
This ensures consistent usage of the new mocking framework throughout the test class.
clevertap-core/src/test/java/com/clevertap/android/sdk/leanplum/LeanplumCtTest.kt (4)
4-4
: Successfully migrated to MockK imports.The import change is part of the successful migration from Mockito to MockK.
27-32
: Good conversion to MockK verification syntax.The Mockito verification has been properly replaced with MockK's cleaner block-based syntax.
47-58
: MockK verification looks good.The test properly uses MockK's verification syntax with the nested map structure.
68-73
: All verifications successfully converted to MockK.All verification blocks have been consistently and correctly migrated to MockK's syntax, maintaining the same test assertions while using a more Kotlin-idiomatic approach.
Also applies to: 86-94, 105-105, 115-122, 131-137, 147-154, 164-173, 180-184, 199-211, 225-237, 249-259
clevertap-core/src/test/java/com/clevertap/android/sdk/CleverTapFactoryTest.kt (3)
7-8
: Successfully migrated to MockK imports.Imports have been correctly updated from Mockito to MockK equivalents.
113-119
: Good implementation of MockK's static mocking.The Mockito static mocking has been replaced with MockK's
mockkStatic
block syntax, which provides better scoping of the mocked static methods.
150-157
: Consistent pattern for static mocking.All instances of static mocking have been consistently converted to use MockK's block-based syntax, maintaining the same test behavior.
Also applies to: 164-171
clevertap-core/src/test/java/com/clevertap/android/sdk/variables/ParserTest.kt (4)
7-7
: Successfully imported MockK utilities.The import statement correctly includes all necessary MockK utilities.
35-36
: Properly migrated to MockK's spyk.The test now uses MockK's
spyk
function instead of Mockito'sspy
, maintaining the same functionality.Also applies to: 38-38
47-48
: Clear verification count with MockK.MockK's
exactly = 1
parameter makes the expected invocation count more explicit than Mockito's equivalent.
56-61
: Comprehensive migration of verification blocks.All verification blocks have been thoroughly converted to MockK syntax with explicit invocation counts, maintaining the same test assertions.
Also applies to: 77-113, 129-165
clevertap-core/src/test/java/com/clevertap/android/sdk/StorageHelperTest.kt (3)
9-10
: Successfully imported MockK utilities.Import statements have been updated to use MockK's mocking and verification utilities.
359-359
: Basic mock creation and verification migrated to MockK.The test now uses MockK's
mockk()
function and block-based verification syntax.Also applies to: 361-363
368-368
: Consistent use of MockK for second test case.The migration pattern is consistently applied across multiple test methods.
Also applies to: 370-372
clevertap-core/src/test/java/com/clevertap/android/sdk/inbox/CTInboxListViewFragmentTest.kt (5)
5-6
: Imports correctly updated for MockK.MockK imports have properly replaced Mockito imports for spying and verification.
8-10
: JUnit imports properly updated.Changed from wildcard imports to specific imports, which improves code clarity.
53-53
: Correctly migrated from Mockito.spy to MockK's spyk.The spy object creation is properly converted to MockK's equivalent syntax.
71-73
: Properly converted Mockito verification to MockK verification syntax.Changed from
Mockito.verify(obj).method()
withatLeastOnce()
to MockK's block-based syntax withatLeast = 1
.
214-216
: Correctly migrated "never()" verification to MockK's equivalent.Changed from
Mockito.verify(obj, never()).method()
toverify(exactly = 0) { ... }
, which is the correct MockK equivalent.clevertap-core/src/test/java/com/clevertap/android/sdk/displayunits/CTDisplayUnitControllerTest.kt (2)
6-11
: Imports properly updated for MockK and JUnit.MockK imports have correctly replaced Mockito imports, and wildcard JUnit imports have been replaced with specific imports.
55-61
: Successfully migrated static mocking from Mockito to MockK.The static mocking approach has been correctly transformed:
- Changed from Mockito's
mockStatic()
to MockK's block-basedmockkStatic() { ... }
- Replaced Mockito's
when().thenThrow()
with MockK'severy { ... } throws
- Properly contained the test code within the mockkStatic block
This change maintains the same test behavior while adopting MockK's more structured approach to static mocking.
clevertap-core/src/test/java/com/clevertap/android/sdk/LocationManagerTest.kt (5)
8-11
: MockK imports properly added.Required imports for MockK functionality have been correctly added.
34-42
: Properly migrated mock and spy creation to MockK.The changes show good practices:
- Using
mockk<EventQueueManager>(relaxed = true)
instead of Mockito'smock()
, with the relaxed parameter to reduce stubbing needs- Properly using MockK's
spyk()
function with constructor parameters
69-70
: Successfully migrated Mockito stubbing to MockK.Correctly changed from Mockito's
when(obj.method()).thenReturn(value)
to MockK'severy { obj.method() } returns value
syntax.Also applies to: 84-86
82-83
: Properly created relaxed mocks with MockK.Using
mockk<Future<*>>(relaxed = true)
is a good practice that simplifies testing by allowing unstubbed methods to return default values.Also applies to: 113-114
93-94
: Verification syntax correctly migrated to MockK.Changed from
verify(obj).method()
to MockK's block-basedverify { obj.method() }
syntax.Also applies to: 124-125
clevertap-core/src/test/java/com/clevertap/android/sdk/ApplicationTest.kt (2)
4-6
: Imports correctly updated for MockK.MockK imports have properly replaced Mockito imports.
22-25
: Successfully migrated static mocking and verification to MockK.
- Changed from Mockito's
mockStatic(ActivityLifecycleCallback.class)
to MockK'smockkStatic(ActivityLifecycleCallback::class) { ... }
- Properly contained the test code within the mockkStatic block
- Correctly updated the verification syntax to MockK's style
The migration maintains the same test behavior while adopting MockK's structured approach to static mocking.
clevertap-hms/src/test/java/com/clevertap/android/hms/HmsMessageHandlerTest.kt (5)
12-15
: Successfully migrated imports from Mockito to MockK.The import changes correctly bring in the essential MockK functionality needed for the test:
every
,mockk
, andmockkStatic
.
33-33
: Good implementation of MockK mock creation.The
mockk<HmsNotificationParser>(relaxed = true)
approach is appropriate and provides better Kotlin integration than the previous Mockito implementation. Therelaxed = true
parameter ensures that undefined methods return default values instead of throwing exceptions.
46-50
: Correctly implemented MockK stubbing.The
every { parser.toBundle(any()) } returns bundle
syntax is more idiomatic in Kotlin compared to the Mockito equivalent, making the test more readable and maintainable.
47-53
: Well-implemented static mocking with MockK.The
mockkStatic(CleverTapAPI::class) { ... }
approach with a scoped block is the correct way to implement static mocking in MockK, ensuring proper cleanup after the test.
61-62
: Consistent implementation of mocking throughout the file.The changes to MockK syntax are consistently applied throughout the file, maintaining the same test behavior while using the more Kotlin-friendly MockK framework.
Also applies to: 72-73, 84-89
clevertap-core/src/test/java/com/clevertap/android/sdk/CallbackManagerTest.kt (6)
44-44
: Successfully migrated from Mockito spy to MockK spyk.The
spyk<CTInboxListener>(ib)
syntax is the correct MockK equivalent for creating a spy object and follows Kotlin conventions.
48-50
: Well-implemented verification syntax.The MockK verification block with explicit verification parameters (
atLeast = 1
) is more readable than the Mockito equivalent and better aligns with Kotlin's syntax style.
175-178
: Properly defined spy with interface implementation.The spy creation for the anonymous SyncListener implementation is correct. Empty method implementations are fine in test classes since they're just fulfilling interface requirements.
🧰 Tools
🪛 detekt (1.23.8)
[warning] 176-176: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
[warning] 177-177: This empty block of code can be removed.
(detekt.empty-blocks.EmptyFunctionBlock)
183-185
: Explicit verification count correctly implemented.Using
verify(exactly = N)
with a verification block clearly specifies the expected number of invocations, making the test intention more readable.Also applies to: 189-191
198-200
: Good implementation of MockK stubbing with return value.The
every { deviceInfoSpy.deviceID } returns "motorola"
syntax correctly defines the stubbed behavior in a more Kotlin-idiomatic way.
206-211
: Consistent verification pattern throughout the test class.The changes maintain a consistent pattern for spy creation and verification across all test methods, which makes the test code more maintainable.
Also applies to: 215-216, 220-226, 236-248
clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/ImpressionManagerTest.kt (4)
12-13
: Successfully migrated imports to MockK.The imports have been appropriately updated to use MockK instead of Mockito.
34-35
: Properly initialized MockK relaxed mocks.Using
mockk(relaxed = true)
is the correct approach for creating mocks that return default values for unstubbed methods, which helps minimize boilerplate in tests.
49-49
: Well-implemented stubbing with MockK.The
every { deviceInfo.deviceID } returns "device_id"
syntax correctly uses MockK's fluent API for defining mock behavior.
157-157
: Consistent implementation of clock behavior throughout tests.Every instance of clock mocking has been consistently updated to use MockK's syntax. This pattern is applied uniformly across all test methods, ensuring consistency.
Also applies to: 189-189, 223-223, 258-258, 267-267, 276-276, 285-285, 294-294, 305-305, 332-332, 341-341, 350-350, 359-359, 368-368, 379-379, 633-633
clevertap-core/src/test/java/com/clevertap/android/sdk/task/IOExecutorTest.kt (4)
4-8
: Successfully updated imports for MockK.The imports have been appropriately updated to use MockK's
mockk
andverify
functionality, along with the necessary JUnit imports.
22-27
: Correct implementation of setUp with MockK.The setUp method properly initializes the mock with
mockk(relaxed = true)
. The@Before
annotation isn't needed here since the method overridessetUp()
fromBaseTestCase
, which likely already has the annotation.
45-45
: Consistent verification syntax throughout the class.All verification calls have been updated to use MockK's verification block syntax. This change is consistently applied across all test methods, making the test code more maintainable and readable.
Also applies to: 52-52, 59-59, 68-68, 75-75, 84-84, 90-90, 96-96, 102-102, 108-108, 115-115, 123-123, 130-130
89-90
: Correctly implemented property access verification.The verification of property access (rather than method calls) is properly implemented using MockK's syntax.
Also applies to: 95-96
clevertap-core/src/test/java/com/clevertap/android/sdk/task/MainThreadExecutorTest.kt (3)
6-10
: Clean import replacement for MockK integrationThe imports have been correctly updated to replace Mockito with MockK equivalents and to use specific JUnit imports rather than wildcards, which is good practice.
18-18
: Appropriate MockK relaxed mode usageThe
mockk<Handler>(relaxed = true)
correctly replaces the Mockito mock with MockK's relaxed mode, which provides default return values for unstubbed methods.
23-23
: Correct MockK verification syntaxThe verification syntax has been properly updated to use MockK's DSL-style verification, maintaining the same functional verification as the original Mockito code.
clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/CTFcmMessageHandlerTest.kt (2)
10-15
: Clean import replacement for MockKThe imports have been properly updated to use MockK instead of Mockito, including the necessary static mocking imports.
66-75
: Well-implemented static mocking with MockKThe static mocking implementation has been properly migrated to use MockK's
mockkStatic
approach, which provides better type safety compared to Mockito's static mocking. The exception throwing behavior is correctly implemented using MockK's DSL syntax.clevertap-core/src/test/java/com/clevertap/android/sdk/task/CTExecutorFactoryTest.kt (2)
4-6
: Appropriate MockK importsThe necessary MockK imports for spying and stubbing have been correctly added.
10-32
: Successfully uncommented and updated test classThis test class appears to have been previously commented out and is now properly uncommented and updated to use MockK instead of Mockito. The test methods provide good coverage of the
CTExecutorFactory
class, including exception handling and object uniqueness verification.The spy creation with
spyk
and property stubbing withevery { ... } returns ...
syntax is correctly implemented according to MockK's API.clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmPushProviderTest.kt (3)
5-9
: Correct import replacement for MockKThe imports have been properly updated to use MockK's verification and mocking functionality.
19-25
: Proper setup method migrationThe setup method has been correctly migrated to use MockK's
mockk(relaxed = true)
for creating test doubles. The removal of the@Before
annotation is acceptable since this method is overriding the parent class'ssetUp()
method, which likely already has the@Before
annotation.
30-30
: Consistent verification syntax updateAll verification calls have been uniformly updated to use MockK's
verify(exactly = 1) { ... }
syntax, which is equivalent to Mockito'sverify(..., times(1))
. The consistent application across all test methods shows good attention to detail.Also applies to: 36-36, 42-42, 53-53
clevertap-hms/src/test/java/com/clevertap/android/hms/HmsPushProviderTest.kt (4)
8-9
: Added MockK imports.Properly replaced Mockito imports with MockK equivalents for mocking and verification.
27-30
: Correctly migrated mock creation.The migration from Mockito mocks to MockK has been implemented properly:
- Using
mockk<Type>(relaxed = true)
to create lenient mocks- The
relaxed = true
parameter ensures the mocks behave similarly to Mockito's default behavior
36-37
: Successfully updated verification syntax.The verification syntax has been properly updated from Mockito's method chaining to MockK's DSL with lambdas:
- Using
verify(exactly = 1) { ... }
to explicitly specify invocation counts- Proper usage of matchers like
or(isNull(), any())
andeq(HPS)
in the MockK style
43-44
: Consistent verification pattern applied throughout.The verification pattern has been applied consistently to all test methods, maintaining the same behavior while using MockK's syntax.
Also applies to: 49-50
clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/InAppQueueTest.kt (5)
10-13
: Added required MockK imports.Correctly added all necessary MockK imports to replace Mockito functionality:
confirmVerified
(replaces verifyNoInteractions)every
(replaces when/thenReturn)mockk
(replaces @mock annotations)verify
(replaces verification methods)
34-39
: Successfully migrated from annotation-based mocks to explicit creation.Properly replaced Mockito's annotation-based mock setup with explicit MockK mock creation:
- All mocks are created with
mockk(relaxed = true)
which provides similar behavior to Mockito's default configuration- The
relaxed = true
parameter is essential as it allows unspecified methods to return default values instead of failing
54-55
: Correctly implemented stubbing with MockK.Successfully replaced Mockito's
when(...).thenReturn(...)
with MockK'severy { ... } returns ...
syntax across all test methods, maintaining the same test behavior.Also applies to: 85-86, 101-102, 114-115, 125-126, 136-137, 146-147
60-61
: Properly updated verification syntax.Correctly converted Mockito's
verify(...)
calls to MockK'sverify { ... }
lambda-based syntax throughout the test class, preserving the same verification behavior.Also applies to: 91-92, 107-108, 118-119, 129-130, 147-148
77-78
: Replaced verifyNoInteractions with confirmVerified.Properly replaced Mockito's
verifyNoInteractions(mockInAppStore)
with MockK's equivalentconfirmVerified(mockInAppStore)
to assert that no interactions occurred on the mock.clevertap-core/src/test/java/com/clevertap/android/sdk/validation/ValidatorTest.kt (3)
5-7
: Added proper MockK imports.The imports for MockK functionality (
every
,spyk
) have been correctly added to replace the Mockito equivalent imports.
87-88
: Successfully migrated spy creation.Correctly replaced Mockito's
spy()
with MockK'sspyk()
to create a partial mock of the validator object.
93-94
: Properly updated method stubbing.Successfully replaced Mockito's
when(...).thenReturn(...)
with MockK'severy { ... } returns ...
syntax for stubbing method calls on the spied object. The behavior is preserved while using MockK's more Kotlin-idiomatic syntax.Also applies to: 108-109
clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/ProductConfigSettingsTest.kt (6)
8-12
: Added comprehensive MockK imports.Correctly added all necessary MockK imports to replace Mockito functionality:
every
for stubbingmockk
for creating mocksmockkStatic
for static mockingspyk
for creating spiesverify
for verification
29-31
: Successfully migrated mock creation.Properly replaced Mockito's
mock(FileUtils.class)
with MockK'smockk<FileUtils>(relaxed = true)
to create a lenient mock.
98-104
: Correctly implemented static mocking.Successfully replaced Mockito's static mocking with MockK's
mockkStatic
approach:
- Using the block-based syntax
mockkStatic(CTExecutorFactory::class) { ... }
- Properly stubbing static methods with
every { CTExecutorFactory.executors(...) } returns ...
- Containing the static mocking scope appropriately
111-113
: Properly updated stubbing and verification.Successfully migrated:
- Mockito's
when(...).thenReturn(...)
to MockK'severy { ... } returns ...
- Mockito's
verify(...)
to MockK'sverify { ... }
- Properly using MockK's
any()
matcher to replace Mockito's type-specific matchers
123-128
: Successfully migrated spy creation and exception throwing.Correctly implemented:
- Replacing Mockito's
spy()
with MockK'sspyk()
- Converting Mockito's
when(...).thenThrow(...)
to MockK'severy { ... } throws ...
- Using
verify(exactly = 0) { ... }
to replace Mockito'sverify(..., never())
for verifying that methods were not called
142-148
: Consistently applied MockK patterns throughout.The MockK patterns have been consistently applied throughout the test class, maintaining the same test behavior while using MockK's more Kotlin-idiomatic syntax.
clevertap-core/src/test/java/com/clevertap/android/sdk/login/LoginControllerTest.kt (8)
26-27
: Import statements updated for MockKThe imports have been properly updated to use MockK's static mocking and utility functions.
103-107
: Successfully migrated static mocking to MockKThe code correctly migrates from Mockito's static mocking to MockK's
mockkStatic()
approach, maintaining the same test behavior while using the new framework.
137-138
: Updated to MockK's just runs syntaxCorrectly replaced Mockito's
doNothing().when()
with MockK'sjust runs
syntax for void methods.
139-143
: Static mocking correctly migratedThe static mocking pattern is consistently applied throughout the test class.
172-176
: Consistent static mocking pattern appliedThe migration maintains a consistent pattern for static mocking across all test methods.
207-211
: Completed consistent static mocking migrationAll instances of static mocking have been successfully migrated to MockK's approach.
243-244
: MockK stubbing correctly implementedThe mock behavior is properly defined using MockK's
just runs
syntax for void callback methods.
281-282
: Consistent mock behavior definitionThe same pattern for defining mock behavior is applied consistently throughout the test class.
clevertap-core/src/test/java/com/clevertap/android/sdk/ActivityLifecycleCallbackTest.kt (4)
7-11
: Import statements updated for MockKThe imports have been properly updated to use MockK's verification, mocking, and argument capturing functions.
21-25
: Correctly migrated to MockK relaxed mocksThe test properly replaces Mockito mocks with MockK's
mockk(relaxed = true)
, which simplifies stubbing by providing default behaviors for all methods.
53-66
: Successfully migrated argument capturing and static mockingThis test correctly implements:
- MockK's slot mechanism for argument capturing
- Static mocking with
mockkStatic
- Verification of static method calls
The test logic remains unchanged while using MockK's improved syntax.
70-82
: Completed argument capturing migrationConsistent pattern of argument capturing and verification using MockK's mechanism is properly applied.
clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiWrapperTest.kt (3)
7-13
: Improved import organizationThe imports have been cleaned up to use explicit imports rather than wildcards, making the dependencies clearer.
22-23
: Formatting improvementAdded blank line for better code readability.
36-37
: Consistent formatting appliedBlank lines added between test methods and at the end of the file for better readability and consistent formatting.
Also applies to: 49-50, 65-66
clevertap-core/src/test/java/com/clevertap/android/sdk/inbox/CTInboxControllerTest.kt (9)
9-13
: Import statements updated for MockKThe imports have been properly updated to use MockK's mocking, spying, and verification functions.
36-43
: Successfully migrated to MockK mocks and stubbingReplaced Mockito mocks with MockK's
mockk(relaxed = true)
and updated stubbing syntax to useevery { ... } returns ...
pattern.
56-73
: Complete migration to MockKSuccessfully migrated:
- Static mocking with
mockkStatic
- Spying with
spyk
- Stubbing with
every
- Verification with explicit counts using
verify(exactly = 0)
The test logic remains unchanged while using MockK's syntax.
87-104
: Consistent MockK pattern appliedThe same pattern for static mocking, stubbing, and verification is consistently applied across all test methods.
141-154
: Static mocking correctly implementedThe static mocking approach is consistent with the pattern used throughout the file, ensuring proper test isolation.
191-206
: Consistent verification patternVerification of method calls is consistently implemented using MockK's syntax.
219-236
: MockK verification with explicit countsProperly uses
verify(exactly = 0)
to ensure certain methods are not called, maintaining the same test assertions as before.
250-267
: Multiple verification count correctly migratedSuccessfully migrated verification with multiple calls (
exactly = 2
), maintaining the same test expectations.
293-294
: Consistent end-of-file formattingApplied consistent formatting with a newline at the end of the file.
clevertap-core/src/test/java/com/clevertap/android/sdk/LocalDataStoreTest.kt (10)
16-19
: Looks good - successfully migrated imports from Mockito to MockK.The required MockK imports have been added for the core functionality: every, mockk, spyk, and verify.
53-54
: Migration from Mockito to MockK mock objects is correct.The CryptRepository and CryptFactory mocks have been properly converted to MockK syntax using relaxed mocks, which is a good practice for mock objects where you don't need to verify every interaction.
57-59
: Correct implementation of MockK for database components.The mocks for DBManager, DBAdapter, and UserEventLogDAOImpl are properly set up with the relaxed parameter, which is equivalent to Mockito's lenient mocking behavior.
75-77
: Successfully migrated spy and stubbing to MockK syntax.The spying on localDataStoreWithConfig and stubbing of the database adapter methods have been properly converted to MockK's syntax.
205-206
: Successfully migrated spy objects for context and JSON to MockK.The spy objects for the application context and JSON objects have been properly converted to MockK's spyk() function.
Also applies to: 222-224
209-236
: Verification syntax properly migrated to MockK.The verification calls have been correctly updated to use MockK's verify syntax with explicit counts (exactly = 0, exactly = 1) which is equivalent to Mockito's never() and times(1) verifications.
324-342
: Proper implementation of MockK verification for DAO methods.The verifications for database adapter and DAO methods have been correctly implemented using MockK's verification syntax including the verification that some methods are not called (exactly = 0).
331-332
: Successful migration of stubbing to MockK syntax.The mocking behavior for eventExistsByDeviceIdAndNormalizedEventName and updateEventByDeviceIdAndNormalizedEventName has been properly converted to MockK's every/returns syntax.
347-348
: Test stubs and validations correctly migrated to MockK.All the stubbing for user event log related tests have been properly converted to MockK's syntax with the every/returns pattern matching the test scenarios.
Also applies to: 360-362, 376-377, 401-402, 414-415, 427-428, 440-441, 453-454, 469-470, 482-483, 497-504, 507-508, 517-518
463-464
: Verification count assertions correctly migrated to MockK.The verification with explicit counts (exactly = 1, exactly = 2, exactly = 3) have been properly converted, maintaining the same verification logic as the original Mockito tests.
Also applies to: 489-490, 524-525, 531-533
clevertap-core/src/test/java/com/clevertap/android/sdk/SessionManagerTest.kt (8)
15-18
: Successfully migrated imports from Mockito to MockK.The correct MockK imports have been added to replace the previous Mockito imports.
48-52
: Properly migrated mock objects to MockK syntax.The CryptRepository, CryptFactory, and DBManager mocks have been correctly converted to use MockK's relaxed mocks.
64-67
: Good addition of cleanUp method to handle test state.Adding the cleanUp method that properly resets the CoreMetaData's current activity after tests is a good practice to ensure test isolation.
72-86
: Successfully migrated spy objects and verifications to MockK.The spy objects for SessionManager and verification of method calls have been properly converted to MockK's syntax, maintaining the same verification logic.
93-111
: Correct implementation of spying and verification in the destroySession test.The spy for CoreMetaData and verifications for method calls have been properly migrated to MockK syntax with explicit verification counts.
122-135
: Successfully migrated mock and stubbing for LocalDataStore.The mock creation and behavior stubbing for LocalDataStore have been properly converted to MockK's syntax.
140-154
: Verification logic correctly migrated to MockK in lazyCreateSession test.The spy objects and verification of method calls have been properly converted to MockK's verify with explicit counts.
162-177
: Complex test setup successfully migrated to MockK.The complex test setup with spies and stubbing for the createSession test has been properly converted to MockK's syntax.
clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmSdkHandlerImplTest.kt (9)
12-15
: Successfully migrated imports from Mockito to MockK.The needed MockK imports have been added: every, mockk, mockkStatic, and verify.
30-33
: Mock creation properly migrated to MockK.The mocks for CTPushProviderListener and ManifestInfo have been correctly converted to use MockK's relaxed mocks.
38-41
: Static mocking correctly migrated to MockK's mockkStatic.The static mocking of PackageUtils class has been properly converted to MockK's mockkStatic with lambda syntax.
46-57
: Correctly implemented nested static mocking in MockK.The nested static mocking of PackageUtils and FirebaseApp classes has been properly implemented using MockK's syntax, allowing for proper stubbing of static methods.
63-75
: Successfully migrated complex static mocking to MockK.The complex static mocking setup for the isAvailable_InValid_Manifest_InValid_Config_Json_Returns_False test has been properly converted to MockK's syntax.
80-85
: Exception throwing correctly migrated to MockK.The stubbing of an exception being thrown has been properly converted to MockK's syntax.
90-102
: Static method mocking for isSupported tests correctly implemented.The static mocking of PackageUtils.isGooglePlayStoreAvailable has been properly converted to MockK's syntax.
111-119
: Complex stubbing with multiple static calls correctly migrated.The stubbing chain for getSenderId_Invalid_Manifest_Valid_Config_Json test has been properly converted to MockK's syntax.
137-141
: Verification and exception handling correctly migrated to MockK.The static mocking, exception throwing, and verification in the testRequestToken_Exception_Null_Token test have been properly converted to MockK's syntax.
clevertap-core/src/test/java/com/clevertap/android/sdk/CleverTapAPITest.kt (16)
12-17
: Successfully migrated imports from Mockito to MockK.The required MockK imports have been added: confirmVerified, every, mockk, mockkStatic, slot, and verify.
33-33
: Updated mock implementation class to use Kotlin-specific version.The corestate variable has been updated to use MockCoreStateKotlin instead of MockCoreState, which is likely a more idiomatic implementation for Kotlin tests using MockK.
37-43
: Successfully migrated static mocking to MockK's mockkStatic.The static mocking of CTExecutorFactory and CleverTapFactory classes has been properly converted to MockK's mockkStatic with lambda syntax.
Also applies to: 46-56, 59-65
104-105
: Mock initialization updated to use MockK implementation.The initialization of corestate in the setUp method has been properly updated to use the new MockCoreStateKotlin class.
110-124
: Successfully migrated static mocking and verification in test case.The static mocking of Utils class and verification of behavior in the test_CleverTapAPI_constructor_when_InitialAppEnteredForegroundTime_greater_than_5_secs test have been properly converted to MockK's syntax.
131-145
: Test case correctly migrated to use MockK.The static mocking and verification in the test_CleverTapAPI_constructor_when_InitialAppEnteredForegroundTime_less_than_5_secs test have been properly converted to MockK's syntax.
162-162
: Verification syntax properly migrated to MockK.The verification call for locationManager._setLocation has been correctly updated to use MockK's verify syntax.
209-221
: Argument capturing properly migrated from Mockito to MockK.The ArgumentCaptor has been correctly replaced with MockK's slot mechanism for capturing and verifying arguments.
229-240
: Consistent use of MockK's argument capture mechanism.The slot capture pattern is consistently used here for pushGeofenceEnteredEvent test, replacing Mockito's ArgumentCaptor.
291-302
: Complex verification correctly migrated to MockK.The verification of multiple method calls with specific arguments has been properly converted to MockK's syntax.
315-325
: Nested verification correctly migrated to MockK.The verification of pushProviders behavior with nested method calls has been properly converted to MockK's syntax.
336-342
: Negative verification properly migrated to MockK.The verification that a method is not called has been properly converted from Mockito's verify(never()) to MockK's verify(exactly = 0).
406-422
: Mock controller and verification with confirmVerified correctly implemented.The mock creation for controller classes and verification with confirmVerified (equivalent to Mockito's verifyNoMoreInteractions) have been properly implemented.
426-442
: Complex mocking scenario correctly migrated to MockK.The complex mocking scenario with multiple verifications has been properly converted to MockK's syntax.
446-462
: Consistent pattern for mock creation and verification across test cases.The pattern for creating mocks and verifying behavior is consistently applied across similar test cases.
Also applies to: 466-482
486-499
: User event log test cases correctly migrated to MockK.All the user event log related test cases have been properly converted to use MockK's every/returns for stubbing and verify for verification.
Also applies to: 503-517, 521-536, 539-553, 556-569
clevertap-core/src/test/java/com/clevertap/android/sdk/ActivityLifeCycleManagerTest.kt (5)
11-16
: Appropriately migrated imports to MockKThe imports have been correctly updated to use MockK equivalents in place of Mockito imports. This includes all necessary imports for mocking, spying, verification, and argument capturing functionality.
40-42
: Correctly migrated to MockK initialization patternsThe code now uses
MockCoreStateKotlin
and proper MockK initialization syntax. This matches MockK's idiomatic Kotlin approach compared to Mockito's Java-style mocking.
84-96
: Successfully migrated mock objects and verification syntaxThe test now correctly uses MockK's
mockk()
for mocking objects,spyk()
for spy objects, and theverify { }
block syntax for verifications. The migration maintains the same verification behavior with MockK's more expressive syntax.
107-111
: Properly migrated mock initializationsThe migration correctly initializes mock objects using MockK's syntax while preserving the original test's intent.
117-148
: Successfully migrated static mocking and argument capturingThe test now uses MockK's
mockkStatic()
for static mocking,slot()
for argument capturing, and proper nesting of static mocking blocks. This complex test section migrated well, maintaining the original verification behavior.clevertap-core/src/test/java/com/clevertap/android/sdk/featureFlags/CTFeatureFlagsControllerTest.kt (6)
14-18
: Appropriate MockK import additionsThe imports have been correctly updated to use MockK equivalents. All necessary imports for mocking, stubbing, and verification are present.
39-49
: Successfully migrated static mocking and mock initializationsThe test now properly uses MockK's static mocking approach with
mockkStatic()
, and therelaxed = true
parameter for the analytics manager mock is a good practice when you don't need to stub all methods. The spyk initialization for FileUtils is also correctly implemented.
60-67
: Properly migrated static mocking patternThe static mocking of CTExecutorFactory has been correctly migrated to use MockK's approach with the lambda-based scope.
76-78
: Successfully migrated stubbing syntaxThe stubbing has been correctly migrated from Mockito's
when().thenReturn()
style to MockK's more Kotlin-idiomaticevery { } returns
syntax.
119-126
: Properly migrated verification syntaxThe verification syntax now uses MockK's block-based approach which is more readable and type-safe in Kotlin.
185-185
: Correctly migrated negative verificationThe test now properly uses MockK's
verify(exactly = 0) { }
syntax for verifying that a method was not called, which is more readable than Mockito'sverify(mock, never()).method()
approach.clevertap-hms/src/test/java/com/clevertap/android/hms/HmsHandlerTest.kt (6)
9-12
: Appropriate MockK imports addedThe imports have been correctly updated to use MockK equivalents for mocking, stubbing, and verification functionality.
24-26
: Improved field declarations with lateinitThe nullable declarations have been properly changed to use
lateinit
for non-nullable types, which is more idiomatic in Kotlin and eliminates unnecessary null checks.
32-35
: Successfully migrated to MockK initialization patternsThe setup method now correctly uses MockK's
mockk()
with therelaxed = true
parameter, which is a good practice for mocks where you don't need to stub all methods. The spyk initialization is also properly implemented.
41-42
: Correctly migrated stubbing syntax for exceptionsThe test now uses MockK's more readable
every { } throws
syntax for exception stubbing, which is more idiomatic in Kotlin than Mockito's approach.
67-71
: Successfully migrated static mocking patternThe static mocking of HuaweiApiAvailability has been correctly migrated to use MockK's approach with the lambda-based scope, which properly manages the lifecycle of the static mock.
96-103
: Properly migrated complex stubbing and static mockingThe test successfully combines multiple MockK patterns: exception stubbing, complex method stubbing with parameters, and static mocking. The code is now more readable and maintains the same test intent.
clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmMessageListenerServiceTest.kt (4)
8-13
: Successfully migrated imports and improved annotationThe imports have been correctly updated to use MockK. The
@Ignore
annotation now includes a clear reason for why the test is ignored, which is a good practice for maintainability.
23-29
: Removed @before annotation and properly migrated mock creationThe setup method correctly initializes the mock using MockK's
mockk(relaxed = true)
syntax. Note that the@Before
annotation has been removed - this is acceptable as long assetUp()
is called by the parent class's@Before
method.
32-37
: Successfully simplified test with MockK verificationThe test has been simplified by removing unnecessary try-catch blocks and using MockK's cleaner verification syntax. The
exactly = 1
parameter explicitly communicates that the method should be called exactly once.
40-45
: Properly migrated verification to MockK syntaxThe test now uses MockK's verification syntax which is more readable and idiomatic in Kotlin. The use of
any()
for matchers is correctly implemented.clevertap-core/src/test/java/com/clevertap/android/sdk/task/PostAsyncSafelyExecutorTest.kt (3)
4-10
: Imports correctly updated for MockKThe Mockito imports have been properly replaced with their MockK equivalents.
23-23
: Good use of relaxed mockUsing
mockk(relaxed = true)
is appropriate here as it allows non-stubbed methods to return default values instead of throwing exceptions, which is beneficial for ExecutorService that has many methods.
39-39
: Correctly converted verification syntaxThe Mockito verification calls have been properly migrated to MockK's
verify { ... }
syntax with appropriate argument matchers.Also applies to: 47-47, 62-62, 103-103, 109-109, 115-115, 121-121, 133-133, 141-141, 154-154
clevertap-core/src/test/java/com/clevertap/android/sdk/login/ConfigurableIdentityRepoTest.kt (4)
9-11
: Imports correctly updated for MockKThe Mockito imports have been properly replaced with their MockK equivalents.
26-30
: Good use of relaxed mocksUsing
mockk(relaxed = true)
is appropriate for these dependencies, allowing non-stubbed methods to return default values rather than throwing exceptions.
78-79
: Correctly converted stubbing syntaxThe Mockito
when(...).thenReturn(...)
calls have been properly migrated to MockK'severy { ... } returns ...
syntax.Also applies to: 102-103, 127-128, 153-154, 173-174
87-88
: Improved verification with explicit count assertionsThe migration to MockK's
verify(exactly = n)
syntax makes the expected number of invocations more explicit than Mockito's default behavior. This is a good practice for clarity.Also applies to: 111-112, 136-137, 162-163
clevertap-core/src/test/java/com/clevertap/android/sdk/pushnotification/fcm/FcmNotificationBundleManipulationTest.kt (3)
7-9
: Imports correctly updated for MockKThe Mockito imports have been properly replaced with their MockK equivalents.
23-23
: Good use of relaxed mockUsing
mockk(relaxed = true)
is appropriate for the RemoteMessage mock, allowing non-stubbed methods to return default values instead of throwing exceptions.
33-34
: Correctly converted stubbing syntaxThe Mockito
when(...).thenReturn(...)
calls have been properly migrated to MockK'severy { ... } returns ...
syntax.Also applies to: 51-52, 68-69, 85-86
clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/DefaultXmlParserTest.kt (5)
6-10
: Imports correctly updated for MockKThe Mockito imports have been properly replaced with their MockK equivalents.
22-23
: Good use of relaxed mocksUsing
mockk(relaxed = true)
is appropriate for these resource objects, allowing non-stubbed methods to return default values instead of throwing exceptions.
28-30
: Correctly migrated spying and stubbing syntaxMockito spies and stubs have been correctly migrated to MockK's
spyk
andevery { } returns
syntax.
33-33
: Improved verification with explicit countThe migration to MockK's
verify(exactly = 0)
syntax is more explicit than Mockito'sverify(never())
, which is a good practice for clarity.
1-35
:✅ Verification successful
Verify if test coverage is maintained
According to the AI summary, a test method
test_getDefaultsFromXml
was removed. While this might have been due to migration challenges, please ensure that test coverage hasn't been reduced by removing this test case.
🏁 Script executed:
#!/bin/bash # Find all test files that might contain getDefaultsFromXml tests echo "Searching for other test files that might cover getDefaultsFromXml functionality:" rg -l "getDefaultsFromXml" --glob="*.kt" --glob="*.java" clevertap-core/src/test/Length of output: 451
🏁 Script executed:
#!/bin/bash # Inspect CTProductConfigControllerTest for getDefaultsFromXml usage and coverage rg -n "getDefaultsFromXml" -A5 clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/CTProductConfigControllerTest.ktLength of output: 469
Test coverage for getDefaultsFromXml is maintained
- DefaultXmlParserTest covers the null-resources scenario in
test_getDefaultsFromXml_whenContextResourcesAreNull_ParserMethodShouldNotGetCalled
.- CTProductConfigControllerTest invokes
xmlParser.getDefaultsFromXml(application, resId)
(lines 339–342), verifying the normal parsing flow.No missing tests for
getDefaultsFromXml
were found—coverage remains intact.clevertap-core/src/test/java/com/clevertap/android/sdk/network/NetworkManagerTest.kt (8)
8-8
: Successful migration from MockCoreState to MockCoreStateKotlinThe import was properly updated as part of the Mockito to MockK transition.
24-26
: Clean import changes for MockKThe imports have been correctly updated to use MockK's verification and stubbing methods.
46-47
: Successfully replaced Mockito mocking with MockKThe
ctApiWrapper
mock is now created using MockK'smockk()
and stubbed using the idiomaticevery { ... } returns ...
syntax.Also applies to: 50-51
55-58
: Correctly implemented MockK verificationThe test properly uses MockK's relaxed mocking and verification syntax, which is more idiomatic for Kotlin.
62-66
: Proper conversion to MockK's exact verification countThe verification properly uses MockK's
exactly = 0
parameter to verify that a method was not called, replacing Mockito'sverify(mock, never())
.
70-74
: Consistent MockK pattern applicationThe test maintains the same verification logic while using MockK's syntax, ensuring the test's behavior remains unchanged.
78-90
: Proper implementation of MockK in complex test caseThe more complex test case with multiple assertions has been correctly migrated to use MockK's patterns.
157-157
: Successfully migrated to MockCoreStateKotlinThe test now uses the Kotlin version of the mock object in the
provideNetworkManager
method.clevertap-core/src/test/java/com/clevertap/android/sdk/CTWebInterfaceTest.kt (7)
7-7
: Well-structured import for MockK libraryThe star import for MockK is appropriate here as multiple MockK features are used throughout the test.
43-47
: Proper MockK implementation with relaxed modeThe test correctly uses MockK's relaxed mode, which allows unspecified method calls to return default values instead of throwing exceptions.
62-67
: Consistent implementation in loop-based testThe test correctly creates mocks inside the loop and uses MockK's verification syntax with the proper
exactly = 1
parameter.
103-111
: Properly migrated verification for null argumentsThe tests for null arguments now use MockK's verification syntax with the correct
exactly = 0
parameter to assert methods weren't called.
196-225
: Successfully migrated complex verification structureThe nested verification structure has been correctly converted to MockK's more readable and idiomatic syntax.
305-324
: Well-structured complex verification with parametersThe verification with complex parameters has been properly converted to MockK syntax while maintaining the same semantic meaning.
370-391
: Consistent parameter handling in MockK verificationsAll parameter verifications maintain consistent use of MockK's verification syntax throughout the test file.
test_shared/src/main/java/com/clevertap/android/shared/test/BaseTestCase.kt (3)
8-14
: Clean imports for MockK and explicit JUnit annotationsThe imports have been properly updated to use MockK instead of Mockito, and the JUnit annotations are now more explicitly imported.
41-45
: Proper @before annotation and MockK implementationThe
setUp()
method is now explicitly annotated with@Before
and thecleverTapAPI
mock is created using MockK's relaxed mode.
59-62
: Essential MockK cleanup method addedThe addition of the
cleanUp()
method withclearAllMocks()
is crucial for proper MockK usage, as it ensures mocks from one test don't affect others.clevertap-hms/src/test/java/com/clevertap/android/hms/HmsMessageServiceTest.kt (4)
9-12
: Clean MockK import structureThe imports have been properly updated to use MockK features relevant to this test class.
20-20
: Useful @ignore annotation with clear rationaleThe
@Ignore
annotation provides a clear reason for disabling the test, indicating plans to refactor for better dependency injection.
29-32
: Well-implemented MockK spy and property stubbingThe test properly uses MockK's
spyk
with private call recording enabled and uses theevery { ... } returns ...
syntax for property stubbing.
36-47
: Simplified test methods with appropriate verificationThe test methods have been simplified by removing unnecessary try-catch blocks while maintaining the same test logic with MockK's verification syntax.
clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/CTProductConfigControllerTest.kt (7)
13-17
: Successful migration to MockK importsThe import statements have been properly updated to use MockK instead of Mockito, which aligns with the project's goal of migrating test frameworks.
39-65
: Properly implemented MockK static mocking and test setupThe test setup has been correctly migrated from Mockito to MockK:
mockkStatic
is used forCTExecutorFactory
mocking- Relaxed mocks are used appropriately with
mockk(relaxed = true)
- MockK's
every { ... } returns ...
syntax replaces Mockito's stubbing syntaxThis implementation correctly preserves the test's original intent while using MockK's idiomatic approach.
82-84
: Verification syntax correctly updated to MockK styleThe verification calls have been properly updated to use MockK's verification syntax, which differs significantly from Mockito's approach.
119-132
: Successfully implemented test with MockK static mockingThe
test_Reset
test method correctly uses MockK's approach to static mocking and verification. The test logic has been preserved while adapting to the new mocking framework.
159-184
: Correctly implemented complex test case with MockKThe
test_activate
test method has been successfully migrated to use MockK's syntax for mocking, stubbing, and verification. The test logic and assertions remain unchanged.
274-284
: Verification count syntax properly migratedThe test correctly uses MockK's
verify(exactly = 0)
syntax to verify that methods were not called, which is equivalent to Mockito'sverify(never())
.
331-350
: Complex object mocking and verification successfully migratedThe test successfully migrates a complex case involving
DefaultXmlParser
mocking and verification. The implementation correctly preserves the original test intent while using MockK's syntax.clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/evaluation/LimitsMatcherTest.kt (5)
17-22
: Well-structured test setup with MockKThe test class setup has been properly migrated to use MockK. The
setUp()
method now correctly initializes the test dependencies using MockK's relaxed mocks.
24-63
: Clear test method naming and implementationThe test cases use backtick-delimited method names that clearly describe the behavior being tested. The implementation is clean and follows best practices for arranging the test into setup, action, and verification phases.
65-111
: Comprehensive test coverage for session and minutes limit typesThese test cases methodically test both the positive (limit not reached) and negative (limit reached) scenarios for session and minutes limit types. This approach ensures robust test coverage.
113-175
: Well-structured test cases for seconds and hours limit typesThe tests for seconds and hours limits follow the same clear pattern as previous tests, maintaining consistency throughout the test class.
177-266
: Complete coverage for all limit typesThe test suite has been expanded to include test cases for all limit types (days, weeks, ever, onEvery, onExactly). Each type is tested for both limit reached and not reached scenarios, providing comprehensive coverage. This expansion beyond the basic migration demonstrates good testing discipline.
clevertap-core/src/test/java/com/clevertap/android/sdk/EventQueueManagerTest.kt (6)
18-25
: Comprehensive MockK import statementsAll necessary MockK imports have been added to replace Mockito functionality, including specialized imports for
runs
,just
, andslot
that are used for argument capturing and handling void methods.
42-71
: Successfully migrated core test setup to MockKThe test setup has been properly migrated to use
MockCoreStateKotlin
instead of Mockito'sMockCoreState
. The initialization of theEventQueueManager
with spied and mocked dependencies follows MockK's conventions.
76-88
: Added helper method for repeated mock setupThe new
withMockExecutors
helper method significantly reduces code duplication by centralizing the static mocking ofCTExecutorFactory.executors
.
203-210
: Properly migrated argument capturing to MockK's slot systemThe test correctly uses MockK's
slot()
mechanism to capture and verify arguments passed to mocked methods, replacing Mockito'sArgumentCaptor
.
543-557
: Effectively captured and verified complex JSON objectsThe test successfully migrates complex verification involving JSON objects, capturing them with slots and then asserting on their properties.
628-669
: Correctly migrated nested static mockingThe test properly handles nested static mocking of
IdentityRepoFactory
within thewithMockExecutors
block, showing good understanding of MockK's scoping rules.
Add hamcrest as an explicit test dependency since it is used in the tests
…raries Remove redundant test libraries
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (20)
clevertap-core/build.gradle
(0 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/UtilsTest.kt
(0 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/db/DBAdapterTest.kt
(0 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/customtemplates/CustomTemplateTest.kt
(12 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/customtemplates/JsonTemplatesProducerTest.kt
(9 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/images/preload/FilePreloaderCoroutineTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiWrapperTest.kt
(5 hunks)clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/ProductConfigUtilTest.kt
(0 hunks)clevertap-geofence/build.gradle
(0 hunks)clevertap-hms/src/test/java/com/clevertap/android/hms/HuaweiNotificationParserTest.kt
(2 hunks)clevertap-pushtemplates/src/androidTest/java/com/clevertap/android/pushtemplates/ExampleInstrumentedTest.kt
(0 hunks)clevertap-pushtemplates/src/test/java/com/clevertap/android/pushtemplates/ExampleUnitTest.kt
(0 hunks)gradle-scripts/commons.gradle
(0 hunks)gradle/libs.versions.toml
(2 hunks)instantapp/src/androidTest/java/com/clevertap/demo/ExampleInstrumentedTest.kt
(0 hunks)instantapp/src/test/java/com/clevertap/demo/ExampleUnitTest.kt
(0 hunks)sample/src/test/java/com/clevertap/demo/ExampleUnitTest.java
(0 hunks)test_shared/build.gradle
(1 hunks)test_shared/src/androidTest/java/com/clevertap/test_shared_1/ExampleInstrumentedTest.java
(0 hunks)test_shared/src/main/java/com/clevertap/android/shared/test/TestActivity.kt
(1 hunks)
💤 Files with no reviewable changes (12)
- clevertap-core/src/test/java/com/clevertap/android/sdk/product_config/ProductConfigUtilTest.kt
- clevertap-core/src/test/java/com/clevertap/android/sdk/UtilsTest.kt
- gradle-scripts/commons.gradle
- clevertap-pushtemplates/src/test/java/com/clevertap/android/pushtemplates/ExampleUnitTest.kt
- clevertap-core/src/test/java/com/clevertap/android/sdk/db/DBAdapterTest.kt
- clevertap-core/build.gradle
- sample/src/test/java/com/clevertap/demo/ExampleUnitTest.java
- instantapp/src/test/java/com/clevertap/demo/ExampleUnitTest.kt
- clevertap-pushtemplates/src/androidTest/java/com/clevertap/android/pushtemplates/ExampleInstrumentedTest.kt
- test_shared/src/androidTest/java/com/clevertap/test_shared_1/ExampleInstrumentedTest.java
- clevertap-geofence/build.gradle
- instantapp/src/androidTest/java/com/clevertap/demo/ExampleInstrumentedTest.kt
✅ Files skipped from review due to trivial changes (4)
- test_shared/src/main/java/com/clevertap/android/shared/test/TestActivity.kt
- clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/customtemplates/JsonTemplatesProducerTest.kt
- clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/images/preload/FilePreloaderCoroutineTest.kt
- clevertap-core/src/test/java/com/clevertap/android/sdk/inapp/customtemplates/CustomTemplateTest.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- clevertap-hms/src/test/java/com/clevertap/android/hms/HuaweiNotificationParserTest.kt
- test_shared/build.gradle
- clevertap-core/src/test/java/com/clevertap/android/sdk/network/api/CtApiWrapperTest.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint-staticChecks-test-build
🔇 Additional comments (2)
gradle/libs.versions.toml (2)
43-43
: Approve addition of Hamcrest for JUnit4 assertions
The newhamcrest = "3.0"
version andtest_hamcrest
library entry are correctly added to support matcher-based assertions under JUnit4.Also applies to: 119-119
40-40
:✅ Verification successful
Verify the MockK version bump
Themockk
version variable was updated to1.14.2
. Please confirm this aligns with the MockK features your tests rely on and that no compatibility issues arise.Run the following to check the latest release:
🏁 Script executed:
#!/bin/bash # Verify the latest MockK version from Maven Central curl -s https://repo1.maven.org/maven2/io/mockk/mockk/maven-metadata.xml \ | grep -oPm1 "(?<=<release>)[^<]+"Length of output: 116
MockK version update verified
The bump to1.14.2
matches the latest release on Maven Central. No further version changes are needed. Please ensure your tests remain compatible with MockK 1.14.2.
Convert Geofence tests to Kotlin
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: 4
🧹 Nitpick comments (13)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/BaseTestCase.kt (1)
30-73
: Consider using Kotlin's built-in deep equality or a testing library.The Bundle comparison logic is comprehensive but could be simplified. Consider these alternatives:
Option 1: Use a testing library like AssertK or Truth for Bundle comparison:
+import com.google.common.truth.Truth.assertThat +// In test usage: +assertThat(actual).isEqualTo(expected)Option 2: Simplify using Kotlin's approach:
-fun areEqual(expected: Bundle?, actual: Bundle?): Boolean { - // ... current implementation -} +private fun bundleToMap(bundle: Bundle?): Map<String, Any?> { + return bundle?.keySet()?.associateWith { key -> + val value = bundle.get(key) + if (value is Bundle) bundleToMap(value) else value + } ?: emptyMap() +} + +fun areEqual(expected: Bundle?, actual: Bundle?): Boolean { + return bundleToMap(expected) == bundleToMap(actual) +}clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationFactoryTest.kt (2)
38-51
: Consider using assertThrows for better exception testing.While
@Test(expected = IllegalStateException::class)
works, consider using JUnit'sassertThrows
for more precise exception testing:-@Test(expected = IllegalStateException::class) -fun testCreateLocationAdapterTC2() { +@Test +fun testCreateLocationAdapterTC2() { // when play service apk not available mockkStatic(Utils::class) { every { Utils.isFusedLocationApiDependencyAvailable() } returns true mockkStatic(GoogleApiAvailability::class) { every { GoogleApiAvailability.getInstance() } returns googleApiAvailability every { googleApiAvailability.isGooglePlayServicesAvailable(application) } returns ConnectionResult.SERVICE_MISSING - CTLocationFactory.createLocationAdapter(application) + Assert.assertThrows(IllegalStateException::class.java) { + CTLocationFactory.createLocationAdapter(application) + } } } }This provides better error messages and allows you to assert on the exception message if needed.
53-77
: Consistent test pattern for remaining failure cases.The test cases TC3 and TC4 follow the same pattern as TC2, testing different failure scenarios. The same suggestion about using
assertThrows
applies here for better exception handling.clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.kt (1)
22-39
: Well-structured test data with comprehensive settings.The predefined JSON object contains all necessary fields for testing geofence settings. The values appear reasonable for test scenarios.
Note: The field
"last_geo_notification_responsiveness": 0
is included in the JSON but not used in thegetSettings
method. Consider either using it or documenting why it's present.clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationUpdateReceiverTest.kt (3)
41-45
: Consider using a more idiomatic approach for async completion tracking.Using an array to track completion state is not the most idiomatic Kotlin approach. Consider using
AtomicBoolean
orCompletableDeferred
for cleaner async testing.- val isFinished = arrayOf(false) - - every { pendingResult.finish() } answers { - isFinished[0] = true - } + val isFinished = AtomicBoolean(false) + + every { pendingResult.finish() } answers { + isFinished.set(true) + }And update the await condition:
- await().until { isFinished[0] } + await().until { isFinished.get() }
36-36
: Improve test method names for better readability.The current test method names are not very descriptive. Consider using more expressive names that clearly indicate the test scenario.
- fun testOnReceiveWhenLastLocationNotNull() { + fun `should process location updates and finish pending result when location result is valid`() { - fun testOnReceiveWhenLocationResultIsNull() { + fun `should finish pending result immediately when intent is null`() {Also applies to: 72-72
37-39
: Extract common test setup to reduce code duplication.Both test methods have similar setup for creating receiver spy and configuring the pending result mock. Consider extracting this to a helper method.
+ private fun createReceiverSpy(): CTLocationUpdateReceiver { + val receiver = CTLocationUpdateReceiver() + val spy = spyk(receiver) + every { spy.goAsync() } returns pendingResult + return spy + } @Test - fun testOnReceiveWhenLastLocationNotNull() { - val receiver = CTLocationUpdateReceiver() - val spy = spyk(receiver) - every { spy.goAsync() } returns pendingResult + fun testOnReceiveWhenLastLocationNotNull() { + val spy = createReceiverSpy()Also applies to: 73-75
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceFactoryTest.kt (1)
23-23
: Improve test method names for better readability.The current test method names using TC1, TC2, etc. are not descriptive. Consider using more expressive names that clearly indicate the test scenario.
- fun testCreateGeofenceAdapterTC1() { + fun `should create geofence adapter when all dependencies are available`() { - fun testCreateGeofenceAdapterTC2() { + fun `should throw IllegalStateException when Google Play Services is missing`() { - fun testCreateGeofenceAdapterTC3() { + fun `should throw IllegalStateException when Google Play Services is disabled`() { - fun testCreateGeofenceAdapterTC4() { + fun `should throw IllegalStateException when fused location dependency is not available`() {Also applies to: 40-40, 56-56, 72-72
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.kt (2)
32-32
: Improve test method names for better readability.The current test method names are not very descriptive. Consider using more expressive names that clearly indicate the test scenario.
- fun testOnReceiveWhenIntentIstNull() { + fun `should not trigger async processing when intent is null`() { - fun testOnReceiveWhenIntentNotNullTC1() { + fun `should process boot event and finish pending result when API initialization succeeds`() { - fun testOnReceiveWhenIntentNotNullTC2() { + fun `should process boot event and finish pending result when API initialization fails`() { - fun testOnReceiveWhenIntentNotNullTC3() { + fun `should log missing permission and skip async processing when fine location permission missing`() { - fun testOnReceiveWhenIntentNotNullTC4() { + fun `should log missing permission and skip async processing when background location permission missing`() {Also applies to: 42-42, 78-78, 116-116, 147-147
49-54
: Consider extracting common async completion setup.Similar to the first test file, both async test methods use the same array-based completion tracking pattern. Consider extracting this to a helper method and using more idiomatic Kotlin approaches.
+ private fun setupAsyncCompletion(): AtomicBoolean { + val isFinished = AtomicBoolean(false) + every { pendingResult.finish() } answers { + isFinished.set(true) + } + return isFinished + }Also applies to: 84-89
clevertap-geofence/src/test/java/com/clevertap/android/geofence/PendingIntentFactoryTest.kt (1)
22-32
: Fix misleading test comment.The comment states "when pendingIntent flag is no create" but the test is actually checking
FLAG_UPDATE_CURRENT
.@Test fun testGetPendingIntentForFlagUpdateCurrent() { - // when pendingIntent flag is no create + // when pendingIntent flag is update current val actual = PendingIntentFactory.getPendingIntent( application, PendingIntentFactory.PENDING_INTENT_GEOFENCE, PendingIntent.FLAG_UPDATE_CURRENT ) Assert.assertNotNull(actual) }clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceTaskManagerTest.kt (1)
79-81
: Consider using MockK for CTGeofenceTask implementations.The repeated no-op implementations of
setOnCompleteListener
could be simplified using MockK'severy
blocks.-override fun setOnCompleteListener(onCompleteListener: OnCompleteListener) { - // no-op -}You could create a helper function or use MockK to create these task instances:
private fun createMockTask(executeAction: () -> Unit): CTGeofenceTask { return mockk<CTGeofenceTask> { every { execute() } answers { executeAction() } every { setOnCompleteListener(any()) } just Runs } }Also applies to: 102-104, 114-116, 141-143, 175-177
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceAPITest.kt (1)
52-67
: Consider using a test-specific factory for singleton cleanup.The reflection-based cleanup of singleton instances works but is brittle. Consider introducing a test-specific factory or reset method in the production code to avoid reflection usage.
- val field = CTGeofenceAPI::class.java.getDeclaredField("ctGeofenceAPI") - field.isAccessible = true - field.set(instance, null) + // Consider adding a test-specific reset method in CTGeofenceAPI + CTGeofenceAPI.resetForTesting()However, if reflection is the only option to maintain singleton integrity in production, the current approach is acceptable.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (43)
clevertap-geofence/build.gradle
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/BaseTestCase.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/BaseTestCase.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceAPITest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceAPITest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceFactoryTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceFactoryTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceReceiverTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceReceiverTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceSettingsTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceSettingsTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceTaskManagerTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceTaskManagerTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationFactoryTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationFactoryTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationUpdateReceiverTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationUpdateReceiverTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GeofenceUpdateTaskTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GeofenceUpdateTaskTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleGeofenceAdapterTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleGeofenceAdapterTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleLocationAdapterTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleLocationAdapterTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/LocationUpdateTaskTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/LocationUpdateTaskTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PendingIntentFactoryTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PendingIntentFactoryTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushGeofenceEventTaskTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushGeofenceEventTaskTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushLocationEventTaskTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushLocationEventTaskTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/TestApplication.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/TestApplication.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/UtilsTest.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/UtilsTest.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceEventFake.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceEventFake.kt
(1 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceJSON.java
(0 hunks)clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceJSON.kt
(1 hunks)
💤 Files with no reviewable changes (21)
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/TestApplication.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceJSON.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceReceiverTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceFactoryTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceTaskManagerTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationFactoryTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/PendingIntentFactoryTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/UtilsTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushLocationEventTaskTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/LocationUpdateTaskTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/GeofenceUpdateTaskTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleGeofenceAdapterTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceSettingsTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleLocationAdapterTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/BaseTestCase.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushGeofenceEventTaskTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceEventFake.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationUpdateReceiverTest.java
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceAPITest.java
✅ Files skipped from review due to trivial changes (3)
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/TestApplication.kt
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceJSON.kt
- clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceEventFake.kt
🧰 Additional context used
🧬 Code Graph Analysis (2)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushGeofenceEventTaskTest.kt (1)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/GeofenceEventFake.kt (4)
getTriggeredLocation
(47-53)getSingleMatchingTriggeredGeofenceList
(36-45)getDoubleMatchingTriggeredGeofenceList
(8-23)getNonMatchingTriggeredGeofenceList
(25-34)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/UtilsTest.kt (1)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.kt (1)
getSettings
(8-20)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint-staticChecks-test-build
🔇 Additional comments (56)
clevertap-geofence/src/test/java/com/clevertap/android/geofence/BaseTestCase.kt (3)
13-14
: LGTM! Proper Android test configuration.The Robolectric configuration with SDK 28 and custom test application is correctly set up for Android unit testing.
19-27
: Good MockK integration in test lifecycle.The setup and cleanup methods properly initialize the test application and clear MockK mocks, ensuring test isolation.
75-84
: Bundle assertion methods are well-designed.The assertion methods provide good error messaging and follow JUnit conventions with overloaded methods.
clevertap-geofence/build.gradle (2)
28-32
: Proper dependency organization for the geofence module.The
compileOnly
dependencies are correctly scoped since this is a library module that depends on the host app providing these dependencies.
34-41
: Well-structured test dependencies after Mockito migration.The consolidation to use
:test_shared
project is a good approach for sharing test utilities across modules. The specific dependencies for Play Services, WorkManager testing, and Awaitility are appropriate for geofence testing scenarios.The comment explaining the Firebase Messaging dependency is helpful for maintainability.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationFactoryTest.kt (2)
12-21
: Good test setup with MockK relaxed mocking.The test extends BaseTestCase properly and uses relaxed mocking for GoogleApiAvailability, which is appropriate for this test scenario.
22-36
: Excellent MockK static mocking pattern.The nested
mockkStatic
blocks are properly structured and the test logic clearly verifies the success case when all dependencies are available.clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceSettingsTest.kt (3)
14-68
: LGTM! Well-structured configuration tests.The test implementation correctly validates both custom and default settings scenarios. Good coverage of edge cases with invalid values being overridden by defaults, and comprehensive verification of all configuration properties.
14-45
: LGTM: Comprehensive custom settings validationThe test thoroughly validates both valid and invalid configuration scenarios:
- Tests all configurable properties with custom values
- Verifies that invalid intervals and displacement values are corrected to safe defaults
- Uses appropriate assertion methods for different data types
- The two-part test (valid then invalid values) provides good coverage
47-68
: LGTM: Complete default settings verificationThe test comprehensively validates all default settings from the builder:
- Covers all configuration properties
- Uses constants from the appropriate classes (GoogleLocationAdapter)
- Properly tests nullability of optional fields
- Assertions are clear and specific
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceFactoryTest.kt (4)
26-36
: Good use of MockK static mocking for dependency testing.The test correctly uses nested
mockkStatic
blocks to isolate different static dependencies and properly verifies the factory behavior under various conditions.
14-21
: LGTM: Proper test setupThe setup correctly initializes the GoogleApiAvailability mock with relaxed behavior, which is appropriate for this testing scenario.
22-37
: LGTM: Proper static mocking with nested scopesThe test correctly uses MockK's nested static mocking pattern:
mockkStatic(Utils::class)
andmockkStatic(GoogleApiAvailability::class)
are properly nested- Mocking setup is clear and scoped appropriately
- Success case verification is straightforward
39-81
: LGTM: Comprehensive error case coverageThe three error test cases provide excellent coverage:
- TC2: Missing Google Play Services
- TC3: Disabled Google Play Services
- TC4: Missing fused location dependency
All tests properly use
@Test(expected = IllegalStateException::class)
and the static mocking is consistent across test cases.clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushLocationEventTaskTest.kt (3)
50-64
: LGTM! Well-structured test for null API scenario.The test correctly verifies that when CleverTap API initialization fails, no location updates are notified and the completion listener is called appropriately when present.
66-85
: LGTM! Comprehensive testing of null future scenario.The test properly verifies logging behavior and completion listener invocation when the future is null.
107-129
: LGTM! Good coverage of future handling with detailed verification.The test correctly verifies that
future.get()
is called and the appropriate log message is recorded.clevertap-geofence/src/test/java/com/clevertap/android/geofence/PendingIntentFactoryTest.kt (3)
34-62
: LGTM! Comprehensive validation of geofence PendingIntent properties.The test thoroughly verifies all aspects of the created PendingIntent including flags, request code, action, and component using Robolectric shadows.
74-102
: LGTM! Good validation of location PendingIntent properties.Similar comprehensive testing for location-type PendingIntent with proper verification of all properties.
114-185
: LGTM! Excellent coverage of PendingIntent lifecycle scenarios.The tests properly cover instance reuse, cancellation effects, and various flag combinations. This ensures the factory behaves correctly with the Android PendingIntent system.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceTaskManagerTest.kt (3)
12-19
: LGTM! Proper singleton pattern testing.Correctly verifies that the same instance is returned on multiple calls.
21-30
: LGTM! Good async testing pattern with Awaitility.The use of array flags and Awaitility for async verification is appropriate and reliable.
51-67
: LGTM! Critical nested call testing for thread safety.This test is particularly valuable as it verifies that nested calls from the same thread return null futures, preventing potential deadlocks or re-entrant execution issues.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceReceiverTest.kt (3)
29-37
: LGTM! Proper handling of null intent scenario.Correctly verifies that
goAsync()
is not called when the intent is null, which is the expected behavior.
39-69
: LGTM! Comprehensive async broadcast receiver testing.Excellent use of spyk for partial mocking, Awaitility for async verification, and
verifyOrder
to ensure proper logging sequence. The async flag pattern is consistent with other tests in the suite.
51-68
: Good use of MockK scoped static mocking.The use of
mockkStatic
with a lambda block ensures proper cleanup and scope isolation, which is a MockK best practice.clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushGeofenceEventTaskTest.kt (3)
48-57
: Excellent static mocking setup for dependency isolation.The static mocking setup properly isolates the class under test by mocking all external dependencies. The use of
mockkStatic
for utility classes and factories ensures controlled test behavior.
174-188
: Good verification of asynchronous operation completion.The test correctly verifies that the
Future.get()
method is called, ensuring that asynchronous geofence event pushing completes synchronously in the test environment. This is crucial for test reliability and avoiding race conditions.
241-261
: Excellent testing of multiple geofence handling.The test properly verifies that multiple geofences are handled correctly by:
- Using
exactly = 2
to verify the correct number of calls- Capturing multiple JSON objects in a list
- Asserting each captured JSON object individually
This ensures robust handling of multiple geofence events.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/UtilsTest.kt (3)
75-108
: Good SDK version testing but ensure cleanup of static fields.The test properly uses
ReflectionHelpers
to modifyBuild.VERSION.SDK_INT
for testing different Android versions. However, ensure that static field modifications don't affect other tests.The test correctly restores the original SDK value at the end, which is good practice for test isolation.
139-178
: Excellent use of nested static mocking.The nested
mockkStatic
blocks properly scope the mocking ofFileUtils
andCleverTapAPI
classes. This ensures that mocks are automatically cleaned up when the block exits, preventing interference between tests.
209-225
: Effective testing of UI thread dispatching.The test correctly verifies that location updates are dispatched on the UI thread by:
- Capturing the Runnable passed to
runOnUiThread
- Executing the captured Runnable manually
- Verifying the listener is called
This ensures proper threading behavior in the utility function.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceAPITest.kt (2)
188-200
: Good use of expected exception testing.The test correctly uses
@Test(expected = IllegalStateException::class)
to verify that the method throws an exception when geofence initialization hasn't been called. This ensures proper error handling for invalid states.
242-278
: Excellent delta time and distance threshold testing.The test properly validates the location processing logic by:
- Setting up past timestamps (40 minutes ago) to satisfy time thresholds
- Using different coordinates to satisfy distance thresholds
- Verifying that location updates are processed correctly
This ensures the geofencing algorithm works as expected.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/GeofenceUpdateTaskTest.kt (3)
47-71
: Comprehensive test scenario with proper verification.The test correctly verifies both the JSON writing and geofence addition operations by:
- Using slot capture to verify the exact JSON written to file
- Using JSONAssert for accurate JSON comparison
- Verifying the correct number of geofences are added
125-144
: Good testing of geofence removal logic.The test properly verifies that old geofences are removed by their IDs when new geofences are available. The use of slot capture to verify the exact ID list passed to the removal method ensures correctness.
146-170
: Effective testing of fallback behavior.The test correctly verifies that when new geofence data is null, the cached geofence data is used as a fallback. This ensures graceful handling of missing or invalid geofence updates.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/LocationUpdateTaskTest.kt (3)
15-50
: Excellent test class structure and MockK migration!The test class demonstrates best practices for MockK usage:
- Proper inheritance from BaseTestCase
- Clean setup/teardown with static mocking/unmocking
- Comprehensive mocking of all dependencies
- Good use of
relaxed = true
for simplifying mock setupThe static mocking cleanup in the
@After
method is particularly important to prevent test interference.
52-142
: Comprehensive test coverage for different execution scenariosThe test methods effectively cover the core logic branches:
- Background location updates enabled/disabled
- Pending intent presence/absence
- Location adapter availability
- Duplicate request detection with logging verification
The verification patterns are clean and focused, properly testing both positive and negative cases.
144-319
: Thorough testing of location update request logicThe remaining test methods provide excellent coverage of the decision logic for when to request location updates based on configuration changes:
- Location fetch mode changes
- Accuracy, interval, displacement parameter changes
- Proper verification of location adapter interactions
The systematic approach with numbered test cases (TC2-TC10) suggests well-organized test planning.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleGeofenceAdapterTest.kt (4)
25-65
: Well-structured test setup with proper dependency mockingThe test setup demonstrates excellent MockK practices:
- Clean static mocking of Google Play Services
- Proper mock initialization with relaxed behavior
- Comprehensive unmocking in teardown to prevent test pollution
The use of
Tasks::class
static mocking is particularly important for testing Google Play Services integration.
67-98
: Excellent edge case coverage for geofence operationsThe test methods properly handle the defensive programming scenarios:
- Null input validation (TC1)
- Empty list handling (TC2)
- Successful operation with proper async task handling (TC3)
The verification of
Tasks.await(task)
ensures proper synchronous waiting in tests, which is crucial for reliable test execution.
100-122
: Sophisticated verification using slot captureThe
testGetGeofencingRequest
method demonstrates advanced MockK testing:
- Using
slot<GeofencingRequest>()
to capture method arguments- Verifying specific properties of the captured request
- Asserting that
INITIAL_TRIGGER_ENTER
is correctly setThis is an excellent pattern for verifying complex object configurations.
124-178
: Comprehensive removal and monitoring testsThe removal and monitoring tests maintain the same high quality:
- Consistent null/empty/valid input testing pattern
- Proper verification of async task completion
- Good testing of
PendingIntent.cancel()
in stop monitoringThe type-specific verification
any<List<String>>()
andany<PendingIntent>()
shows attention to detail in mock verification.clevertap-geofence/src/test/java/com/clevertap/android/geofence/GoogleLocationAdapterTest.kt (4)
37-81
: Excellent WorkManager test configurationThe test setup demonstrates best practices for testing WorkManager integration:
- Proper
SynchronousExecutor
configuration for deterministic test execution- Correct
WorkManagerTestInitHelper.initializeTestWorkManager()
usage- Comprehensive static mocking of location services
The debug logging level configuration helps with test debugging while maintaining clean test output.
83-115
: Thorough verification of location request parameter mappingThe
testApplySettings
method excellently validates the mapping betweenCTGeofenceSettings
and Google'sLocationRequest
:
- Verifies interval, fastest interval, and displacement settings
- Correctly tests priority mapping from accuracy settings
- Uses proper delta comparison for float values
This ensures the adapter correctly translates between the SDK's API and Google's location services.
117-155
: Good testing of location retrieval and error handlingThe tests effectively cover:
- Asynchronous location retrieval with proper callback testing
- Error case when background updates are disabled
- Proper verification that errors are pushed to CleverTap API
The use of
Assert.assertSame()
for location object comparison is appropriate for testing object identity.
157-231
: Sophisticated WorkManager state verificationThe location update tests demonstrate advanced testing techniques:
- Proper WorkManager job lifecycle testing (enqueue → cancel → verify state)
- Testing different fetch modes with appropriate WorkManager behavior
- Verification of
PendingIntent
cleanup in location servicesThe state assertions using
WorkInfo.State.CANCELLED
and checking forENQUEUED
/RUNNING
states show thorough understanding of WorkManager testing.clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTLocationUpdateReceiverTest.kt (3)
24-33
: LGTM: Proper setup with MockK relaxed mocksThe setup method correctly initializes mocks using MockK's
relaxed = true
option, which provides sensible default return values for unstubbed methods. The LocationResult creation is appropriate for testing.
35-69
: Excellent asynchronous test implementationThis test demonstrates proper MockK usage for testing asynchronous broadcast receivers:
- Correctly uses
spyk()
to spy on the receiver instance- Properly mocks
goAsync()
to return a controlledPendingResult
- Uses a completion flag array pattern for async verification
- Employs
verifyOrder
to ensure logging happens in the expected sequence- Uses Awaitility to wait for async completion
The test coverage is comprehensive and the implementation is solid.
71-81
:❌ Incorrect review comment
Fix potential test issue: Missing async handling verification
The test verifies that
pendingResult.finish()
is called when the intent is null, but there's a logical issue: if the intent is null, the receiver likely shouldn't callgoAsync()
in the first place, which meanspendingResult
wouldn't be available to callfinish()
on.
🏁 Script executed:
#!/bin/bash # Description: Check the actual implementation of CTLocationUpdateReceiver to understand the null intent handling # Expected: Find the onReceive method implementation to verify if goAsync() is called when intent is null ast-grep --pattern $'class CTLocationUpdateReceiver { $$$ onReceive($_, $_) { $$$ } $$$ }'Length of output: 103
Let’s locate the actual receiver implementation and see how
onReceive
handles a null intent:
🏁 Script executed:
#!/bin/bash # 1) Find where CTLocationUpdateReceiver is declared rg -n "class CTLocationUpdateReceiver" -A20 # 2) Grep for the onReceive signature to inspect null-intent logic rg -n "fun onReceive" -C5Length of output: 5488
No test issue:
onReceive
always callsgoAsync()
first
The production code inCTLocationUpdateReceiver.java
unconditionally invokesgoAsync()
at the start ofonReceive(...)
(line 38), before any null-intent checks, and then always callsresult.finish()
in its finally block. VerifyingpendingResult.finish()
when theIntent
is null is therefore correct—no test change is needed.Likely an incorrect or invalid review comment.
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.kt (5)
23-29
: LGTM: Proper mock setupThe setup correctly initializes all required mocks with relaxed behavior, providing a clean foundation for the test cases.
31-39
: LGTM: Null intent handling testThe test correctly verifies that when the intent is null, no asynchronous processing (
goAsync()
) is triggered, which is the expected behavior for a broadcast receiver.
41-75
: LGTM: Comprehensive success case testingThe test thoroughly covers the successful initialization scenario:
- Properly mocks all required permissions and initialization
- Uses async completion verification with Awaitility
- Verifies correct logging and pending result handling
- Static mocking is properly nested and scoped
77-113
: LGTM: Initialization failure handlingThis test properly verifies the behavior when
initCTGeofenceApiIfRequired
returns false, ensuring the receiver still completes gracefully with proper logging.
115-144
: LGTM: Fine location permission validationThe test correctly verifies that when
ACCESS_FINE_LOCATION
permission is missing:
- Appropriate debug logs are generated in the correct order
- No asynchronous processing is initiated
- Uses
verifyOrder
to ensure message sequence
clevertap-geofence/src/test/java/com/clevertap/android/geofence/fakes/CTGeofenceSettingsFake.kt
Show resolved
Hide resolved
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.kt
Show resolved
Hide resolved
clevertap-geofence/src/test/java/com/clevertap/android/geofence/PushLocationEventTaskTest.kt
Show resolved
Hide resolved
clevertap-geofence/src/test/java/com/clevertap/android/geofence/CTGeofenceBootReceiverTest.kt
Show resolved
Hide resolved
Remove unused uiautomator dependency
Summary by CodeRabbit
Chores
Tests
Refactor
New Features