Skip to content

Commit d0c7c5e

Browse files
committed
test: update test suites to reflect modernization cleanup changes
- Update BranchApiPreservationManagerTest to remove tests for deprecated API registrations - Remove logout callback adapter tests from CallbackAdapterRegistryTest - Update LegacyBranchWrapperTest to reflect simplified wrapper implementation - Clean up PreservedBranchApiTest by removing tests for deprecated methods - Adjust ModernStrategyDemoTest to align with updated modernization components These test updates correspond to the production code cleanup in the modernization layer and ensure test coverage remains accurate.
1 parent c85920f commit d0c7c5e

File tree

5 files changed

+25
-240
lines changed

5 files changed

+25
-240
lines changed

Branch-SDK/src/test/java/io/branch/referral/modernization/BranchApiPreservationManagerTest.kt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,7 @@ class BranchApiPreservationManagerTest {
171171
assertNotNull("Should return result for getInstance", result)
172172
}
173173

174-
@Test
175-
fun `test handleLegacyApiCall with getAutoInstance method`() {
176-
val manager = BranchApiPreservationManager.getInstance(mockContext)
177-
178-
val result = manager.handleLegacyApiCall("getAutoInstance", arrayOf(mockContext))
179-
180-
assertNotNull("Should return result for getAutoInstance", result)
181-
}
174+
182175

183176
@Test
184177
fun `test handleLegacyApiCall with setIdentity method`() {
@@ -189,14 +182,7 @@ class BranchApiPreservationManagerTest {
189182
assertNotNull("Should return result for setIdentity", result)
190183
}
191184

192-
@Test
193-
fun `test handleLegacyApiCall with resetUserSession method`() {
194-
val manager = BranchApiPreservationManager.getInstance(mockContext)
195-
196-
val result = manager.handleLegacyApiCall("resetUserSession", emptyArray())
197-
198-
assertNotNull("Should return result for resetUserSession", result)
199-
}
185+
200186

201187
@Test
202188
fun `test handleLegacyApiCall with enableTestMode method`() {
@@ -255,7 +241,7 @@ class BranchApiPreservationManagerTest {
255241
// Call multiple methods
256242
manager.handleLegacyApiCall("getInstance", emptyArray())
257243
manager.handleLegacyApiCall("setIdentity", arrayOf("user1"))
258-
manager.handleLegacyApiCall("resetUserSession", emptyArray())
244+
manager.handleLegacyApiCall("enableTestMode", emptyArray())
259245

260246
// Verify analytics are being tracked
261247
val analytics = manager.getUsageAnalytics()

Branch-SDK/src/test/java/io/branch/referral/modernization/ModernStrategyDemoTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,15 @@ class ModernStrategyDemoTest {
111111
println("⚠️ Static enableTestMode not available: ${e.message}")
112112
}
113113

114-
// Test auto instance
115-
val autoInstance = PreservedBranchApi.getAutoInstance(mockContext)
116-
assertNotNull("Auto instance should return wrapper", autoInstance)
117-
println("✅ Static Branch.getAutoInstance() preserved")
114+
// Test regular instance
115+
val instance = PreservedBranchApi.getInstance()
116+
assertNotNull("Instance should return wrapper", instance)
117+
println("✅ Static Branch.getInstance() preserved")
118118

119119
// Verify analytics captured the calls
120120
val usageData = analytics.getUsageData()
121121
assertTrue("Analytics should track getInstance calls",
122122
usageData.containsKey("getInstance"))
123-
assertTrue("Analytics should track getAutoInstance calls",
124-
usageData.containsKey("getAutoInstance"))
125123

126124
println("📈 Static API calls tracked in analytics")
127125
}

Branch-SDK/src/test/java/io/branch/referral/modernization/adapters/CallbackAdapterRegistryTest.kt

Lines changed: 6 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -187,95 +187,19 @@ class CallbackAdapterRegistryTest {
187187
assertTrue("Should handle null callback gracefully", true)
188188
}
189189

190-
@Test
191-
fun `test adaptLogoutCallback with success result`() {
192-
var callbackExecuted = false
193-
var stateChanged = false
194-
var receivedError: BranchError? = null
195-
196-
val callback = object : Branch.BranchReferralStateChangedListener {
197-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
198-
callbackExecuted = true
199-
stateChanged = changed
200-
receivedError = error
201-
}
202-
}
203-
204-
registry.adaptLogoutCallback(callback, true, null)
205-
206-
// Wait a bit for async callback
207-
Thread.sleep(100)
208-
209-
assertTrue("Callback should have been executed", callbackExecuted)
210-
assertTrue("Should indicate state changed", stateChanged)
211-
assertNull("Should have no error", receivedError)
212-
}
190+
213191

214-
@Test
215-
fun `test adaptLogoutCallback with error`() {
216-
var callbackExecuted = false
217-
var stateChanged = false
218-
var receivedError: BranchError? = null
219-
220-
val callback = object : Branch.BranchReferralStateChangedListener {
221-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
222-
callbackExecuted = true
223-
stateChanged = changed
224-
receivedError = error
225-
}
226-
}
227-
228-
val testError = mock(BranchError::class.java)
229-
230-
registry.adaptLogoutCallback(callback, false, testError)
231-
232-
// Wait a bit for async callback
233-
Thread.sleep(100)
234-
235-
assertTrue("Callback should have been executed", callbackExecuted)
236-
assertFalse("Should indicate state not changed", stateChanged)
237-
assertNotNull("Should receive error", receivedError)
238-
assertSame("Should have correct error", testError, receivedError)
239-
}
192+
240193

241-
@Test
242-
fun `test adaptLogoutCallback with null callback`() {
243-
// Should not throw exception with null callback
244-
registry.adaptLogoutCallback(null, true, null)
245-
246-
assertTrue("Should handle null callback gracefully", true)
247-
}
194+
248195

249-
@Test
250-
fun `test adaptLogoutCallback with null result`() {
251-
var callbackExecuted = false
252-
var stateChanged = false
253-
var receivedError: BranchError? = null
254-
255-
val callback = object : Branch.BranchReferralStateChangedListener {
256-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
257-
callbackExecuted = true
258-
stateChanged = changed
259-
receivedError = error
260-
}
261-
}
262-
263-
registry.adaptLogoutCallback(callback, null, null)
264-
265-
// Wait a bit for async callback
266-
Thread.sleep(100)
267-
268-
assertTrue("Callback should have been executed", callbackExecuted)
269-
assertFalse("Should indicate state not changed when result is null", stateChanged)
270-
assertNull("Should have no error", receivedError)
271-
}
196+
272197

273198
@Test
274199
fun `test concurrent callback execution`() {
275-
val latch = CountDownLatch(3)
200+
val latch = CountDownLatch(2)
276201
var callback1Executed = false
277202
var callback2Executed = false
278-
var callback3Executed = false
279203

280204
val callback1 = object : Branch.BranchReferralInitListener {
281205
override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {
@@ -291,23 +215,14 @@ class CallbackAdapterRegistryTest {
291215
}
292216
}
293217

294-
val callback3 = object : Branch.BranchReferralStateChangedListener {
295-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
296-
callback3Executed = true
297-
latch.countDown()
298-
}
299-
}
300-
301218
// Execute callbacks concurrently
302219
registry.adaptInitSessionCallback(callback1, JSONObject(), null)
303220
registry.adaptIdentityCallback(callback2, JSONObject(), null)
304-
registry.adaptLogoutCallback(callback3, true, null)
305221

306222
latch.await(5, TimeUnit.SECONDS)
307223

308224
assertTrue("Callback 1 should have been executed", callback1Executed)
309225
assertTrue("Callback 2 should have been executed", callback2Executed)
310-
assertTrue("Callback 3 should have been executed", callback3Executed)
311226
}
312227

313228
@Test
@@ -326,24 +241,15 @@ class CallbackAdapterRegistryTest {
326241
}
327242
}
328243

329-
val callback3 = object : Branch.BranchReferralStateChangedListener {
330-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
331-
executionOrder.add("callback3")
332-
}
333-
}
334-
335244
// Execute callbacks in sequence
336245
registry.adaptInitSessionCallback(callback1, JSONObject(), null)
337246
Thread.sleep(50)
338247
registry.adaptIdentityCallback(callback2, JSONObject(), null)
339248
Thread.sleep(50)
340-
registry.adaptLogoutCallback(callback3, true, null)
341-
Thread.sleep(50)
342249

343-
assertTrue("Should have executed all callbacks", executionOrder.size >= 3)
250+
assertTrue("Should have executed all callbacks", executionOrder.size >= 2)
344251
assertTrue("Should contain callback1", executionOrder.contains("callback1"))
345252
assertTrue("Should contain callback2", executionOrder.contains("callback2"))
346-
assertTrue("Should contain callback3", executionOrder.contains("callback3"))
347253
}
348254

349255
@Test
@@ -489,7 +395,6 @@ class CallbackAdapterRegistryTest {
489395
fun `test callback with different result types`() {
490396
var initCallbackExecuted = false
491397
var identityCallbackExecuted = false
492-
var logoutCallbackExecuted = false
493398

494399
val initCallback = object : Branch.BranchReferralInitListener {
495400
override fun onInitFinished(referringParams: JSONObject?, error: BranchError?) {
@@ -503,22 +408,14 @@ class CallbackAdapterRegistryTest {
503408
}
504409
}
505410

506-
val logoutCallback = object : Branch.BranchReferralStateChangedListener {
507-
override fun onStateChanged(changed: Boolean, error: BranchError?) {
508-
logoutCallbackExecuted = true
509-
}
510-
}
511-
512411
// Test with different result types
513412
registry.adaptInitSessionCallback(initCallback, JSONObject(), null)
514413
registry.adaptIdentityCallback(identityCallback, "string_result", null)
515-
registry.adaptLogoutCallback(logoutCallback, 123, null)
516414

517415
Thread.sleep(100)
518416

519417
assertTrue("Init callback should have been executed", initCallbackExecuted)
520418
assertTrue("Identity callback should have been executed", identityCallbackExecuted)
521-
assertTrue("Logout callback should have been executed", logoutCallbackExecuted)
522419
}
523420

524421
@Test

Branch-SDK/src/test/java/io/branch/referral/modernization/wrappers/LegacyBranchWrapperTest.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ class LegacyBranchWrapperTest {
103103
assertTrue("Should execute without exception", true)
104104
}
105105

106-
@Test
107-
fun `test resetUserSession`() {
108-
wrapper.resetUserSession()
109-
110-
// Should not throw exception
111-
assertTrue("Should execute without exception", true)
112-
}
106+
113107

114108
@Test
115109
fun `test getFirstReferringParams`() {

0 commit comments

Comments
 (0)