-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add getAnonymousId() API support (#308)
* feat: add getAnonymousId() API support * chore: add test case for getAnonymousId API Added instrumentation test case in the core module to this this feature.
- Loading branch information
1 parent
12e09ca
commit 3e1a67a
Showing
3 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...rc/androidTest/java/com/rudderstack/android/sdk/core/RudderClientInstrumentationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.rudderstack.android.sdk.core; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.core.app.ApplicationProvider; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class RudderClientInstrumentationTest { | ||
Context context; | ||
RudderConfig config; | ||
@Before | ||
public void setUp() { | ||
context = ApplicationProvider.getApplicationContext(); | ||
config = new RudderConfig.Builder() | ||
.withDataPlaneUrl("DATA_PLANE_URL") | ||
.build(); | ||
} | ||
@Test | ||
public void anonymousIdIsValidWhenNotSetExplicitly() { | ||
RudderClient rudderClient = RudderClient.getInstance(context, "WRITE_KEY", config); | ||
|
||
String anonymousId = rudderClient.getAnonymousId(); | ||
|
||
assertNotNull(anonymousId); | ||
assertNotEquals(0, anonymousId.length()); | ||
} | ||
|
||
@Test | ||
public void anonymousIdIsValidWhenExplicitlySetAfterSDKInit() { | ||
RudderClient rudderClient = RudderClient.getInstance(context, "WRITE_KEY", config); | ||
String customAnonymousId = "CUSTOM_ANONYMOUS_ID"; | ||
RudderClient.putAnonymousId(customAnonymousId); | ||
|
||
String anonymousId = rudderClient.getAnonymousId(); | ||
|
||
assertEquals(customAnonymousId, anonymousId); | ||
} | ||
|
||
@Test | ||
public void anonymousIdIsValidWhenExplicitlySetBeforeSDKInit() { | ||
String customAnonymousId = "CUSTOM_ANONYMOUS_ID"; | ||
RudderClient.putAnonymousId(customAnonymousId); | ||
RudderClient rudderClient = RudderClient.getInstance(context, "WRITE_KEY", config); | ||
|
||
String anonymousId = rudderClient.getAnonymousId(); | ||
|
||
assertEquals(customAnonymousId, anonymousId); | ||
} | ||
|
||
@Test | ||
public void anonymousIdIsValidWhenChangedMultipleTimeAfterSDKInit() { | ||
RudderClient rudderClient = RudderClient.getInstance(context, "WRITE_KEY", config); | ||
String firstCustomAnonymousId = "FIRST_CUSTOM_ANONYMOUS_ID"; | ||
RudderClient.putAnonymousId(firstCustomAnonymousId); | ||
|
||
String anonymousIdChangedFirstTime = rudderClient.getAnonymousId(); | ||
|
||
String secondCustomAnonymousId = "SECOND_CUSTOM_ANONYMOUS_ID"; | ||
RudderClient.putAnonymousId(secondCustomAnonymousId); | ||
|
||
String anonymousIdChangedSecondTime = rudderClient.getAnonymousId(); | ||
|
||
assertEquals(firstCustomAnonymousId, anonymousIdChangedFirstTime); | ||
assertEquals(secondCustomAnonymousId, anonymousIdChangedSecondTime); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters