Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding annotations on public APIs #83

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class CustomIdentityFragment : Fragment() {
val isPrimary: Boolean = sharedViewModel.isPrimary.value ?: false

val item = IdentityItem(identifier, authenticatedState, isPrimary)
Identity.removeIdentity(item, namespace)
if (namespace != null) {
Identity.removeIdentity(item, namespace)
}
}

// Advertising identifier features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
Expand All @@ -39,15 +38,6 @@ public class IdentityPublicAPITest {
@Rule
public TestRule rule = new SetupCoreRule();

// --------------------------------------------------------------------------------------------
// Setup
// --------------------------------------------------------------------------------------------

@Before
public void setup() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);
}

// --------------------------------------------------------------------------------------------
// Tests for GetExtensionVersion API
// --------------------------------------------------------------------------------------------
Expand All @@ -60,11 +50,29 @@ public void testGetExtensionVersionAPI() {
// --------------------------------------------------------------------------------------------
// Tests for Register extension API
// --------------------------------------------------------------------------------------------

@Test
public void testRegisterExtensionAPI() throws InterruptedException {
// test
// Identity.registerExtension() is called in the setup method
//noinspection deprecation
Identity.registerExtension();
emdobrin marked this conversation as resolved.
Show resolved Hide resolved

// now register monitor extension and start the hub
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION), null);

// verify that the extension is registered with the correct version details
Map<String, String> sharedStateMap = flattenMap(
getSharedStateFor(IdentityTestConstants.SharedStateName.EVENT_HUB, 5000)
);
assertEquals(
IdentityConstants.EXTENSION_VERSION,
sharedStateMap.get("extensions.com.adobe.edge.identity.version")
);
}

@Test
public void testRegisterExtension_withClass() throws InterruptedException {
// test
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// verify that the extension is registered with the correct version details
Map<String, String> sharedStateMap = flattenMap(
Expand All @@ -82,6 +90,8 @@ public void testRegisterExtensionAPI() throws InterruptedException {

@Test
public void testUpdateIdentitiesAPI() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.updateIdentities(
createIdentityMap("Email", "example@email.com", AuthenticatedState.AUTHENTICATED, true)
Expand Down Expand Up @@ -109,6 +119,8 @@ public void testUpdateIdentitiesAPI() throws Exception {

@Test
public void testUpdateAPI_nullData() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.updateIdentities(null);
waitForThreads(2000);
Expand All @@ -125,6 +137,8 @@ public void testUpdateAPI_nullData() throws Exception {

@Test
public void testUpdateAPI_emptyData() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.updateIdentities(new IdentityMap());
waitForThreads(2000);
Expand All @@ -141,6 +155,8 @@ public void testUpdateAPI_emptyData() throws Exception {

@Test
public void testUpdateAPI_shouldReplaceExistingIdentities() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.updateIdentities(createIdentityMap("Email", "example@email.com"));
Identity.updateIdentities(
Expand Down Expand Up @@ -172,6 +188,8 @@ public void testUpdateAPI_shouldReplaceExistingIdentities() throws Exception {

@Test
public void testUpdateAPI_withReservedNamespaces() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.updateIdentities(createIdentityMap("ECID", "newECID"));
Identity.updateIdentities(createIdentityMap("GAID", "<gaid>"));
Expand Down Expand Up @@ -199,6 +217,8 @@ public void testUpdateAPI_withReservedNamespaces() throws Exception {

@Test
public void testUpdateAPI_multipleNamespaceMap() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
IdentityMap map = new IdentityMap();
map.addItem(new IdentityItem("primary@email.com"), "Email");
Expand Down Expand Up @@ -231,6 +251,8 @@ public void testUpdateAPI_multipleNamespaceMap() throws Exception {

@Test
public void testUpdateAPI_caseSensitiveNamespacesForCustomIdentifiers() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
IdentityMap map = new IdentityMap();
map.addItem(new IdentityItem("primary@email.com"), "Email");
Expand Down Expand Up @@ -261,6 +283,8 @@ public void testUpdateAPI_caseSensitiveNamespacesForCustomIdentifiers() throws E

@Test
public void testGetECID() {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
String ecid = getExperienceCloudIdSync();

Expand All @@ -270,6 +294,8 @@ public void testGetECID() {

@Test
public void testGetExperienceCloudId_nullCallback() {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
try {
Identity.getExperienceCloudId(null); // should not crash
Expand All @@ -284,6 +310,8 @@ public void testGetExperienceCloudId_nullCallback() {

@Test
public void testGetUrlVariables() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
setupConfiguration();
String urlVariables = getUrlVariablesSync();
Expand All @@ -293,6 +321,8 @@ public void testGetUrlVariables() throws Exception {

@Test
public void testGetUrlVariables_nullCallback() {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
try {
Identity.getUrlVariables(null); // should not crash
Expand All @@ -307,6 +337,8 @@ public void testGetUrlVariables_nullCallback() {

@Test
public void testGetIdentities() {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// setup
// update Identities through API
IdentityMap map = new IdentityMap();
Expand All @@ -333,6 +365,8 @@ public void testGetIdentities() {

@Test
public void testGetIdentities_nullCallback() {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
try {
Identity.getIdentities(null); // should not crash
Expand All @@ -347,6 +381,8 @@ public void testGetIdentities_nullCallback() {

@Test
public void testRemoveIdentity() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// setup
// update Identities through API
IdentityMap map = new IdentityMap();
Expand Down Expand Up @@ -382,6 +418,8 @@ public void testRemoveIdentity() throws Exception {

@Test
public void testRemoveIdentity_nonExistentNamespace() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
Identity.removeIdentity(new IdentityItem("primary@email.com"), "Email");
waitForThreads(2000);
Expand All @@ -402,6 +440,8 @@ public void testRemoveIdentity_nonExistentNamespace() throws Exception {

@Test
public void testRemoveIdentity_nameSpaceCaseSensitive() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// setup
// update Identities through API
Identity.updateIdentities(createIdentityMap("Email", "example@email.com"));
Expand All @@ -426,6 +466,8 @@ public void testRemoveIdentity_nameSpaceCaseSensitive() throws Exception {

@Test
public void testRemoveIdentity_nonExistentItem() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// setup
// update Identities through API
Identity.updateIdentities(createIdentityMap("Email", "example@email.com"));
Expand All @@ -450,6 +492,8 @@ public void testRemoveIdentity_nonExistentItem() throws Exception {

@Test
public void testRemoveIdentity_doesNotRemoveECID() throws Exception {
registerExtensions(Arrays.asList(MonitorExtension.EXTENSION, Identity.EXTENSION), null);

// test
String currentECID = getExperienceCloudIdSync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static com.adobe.marketing.mobile.edge.identity.util.TestHelper.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import androidx.annotation.Nullable;
import com.adobe.marketing.mobile.AdobeCallback;
Expand Down Expand Up @@ -53,20 +54,23 @@ public class IdentityFunctionalTestUtil {
* core.
* @param extensions the extensions that need to be registered
* @param configuration the initial configuration update that needs to be applied
* @throws InterruptedException if the wait time for extension registration has elapsed
*/
public static void registerExtensions(
final List<Class<? extends Extension>> extensions,
@Nullable final Map<String, Object> configuration
) throws InterruptedException {
) {
if (configuration != null) {
MobileCore.updateConfiguration(configuration);
}

final ADBCountDownLatch latch = new ADBCountDownLatch(1);
MobileCore.registerExtensions(extensions, o -> latch.countDown());

latch.await(REGISTRATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
try {
latch.await(REGISTRATION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
fail("Failed to register extensions");
}
TestHelper.waitForThreads(2000);
resetTestExpectations();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

import static com.adobe.marketing.mobile.edge.identity.IdentityConstants.LOG_TAG;

import androidx.annotation.NonNull;
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.AdobeCallbackWithError;
import com.adobe.marketing.mobile.AdobeError;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.EventSource;
import com.adobe.marketing.mobile.EventType;
import com.adobe.marketing.mobile.Extension;
import com.adobe.marketing.mobile.ExtensionError;
import com.adobe.marketing.mobile.ExtensionErrorCallback;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.services.Log;
import com.adobe.marketing.mobile.util.DataReader;
Expand All @@ -47,29 +46,27 @@ private Identity() {}
*
* @return The version as {@code String}
*/
@NonNull
public static String extensionVersion() {
return IdentityConstants.EXTENSION_VERSION;
}

/**
* Registers the extension with the Mobile SDK. This method should be called only once in your application class.
*
* @deprecated Use {@link MobileCore#registerExtensions(List, AdobeCallback)} with {@link Identity#EXTENSION} instead.
* @deprecated as of 2.0.0, use {@link MobileCore#registerExtensions(List, AdobeCallback)} with {@link Identity#EXTENSION} instead.
*/
@Deprecated
@SuppressWarnings("deprecation")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we suppressing warnings here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it shows a warning in the IDE when using the registerExtension API so it suppresses that, but you would still see the deprecation message on the API itself

public static void registerExtension() {
MobileCore.registerExtension(
IdentityExtension.class,
new ExtensionErrorCallback<ExtensionError>() {
@Override
public void error(ExtensionError extensionError) {
Log.error(
LOG_TAG,
LOG_SOURCE,
"There was an error registering the Edge Identity extension: " + extensionError.getErrorName()
);
}
}
extensionError ->
Log.error(
LOG_TAG,
LOG_SOURCE,
"There was an error registering the Edge Identity extension: " + extensionError.getErrorName()
)
);
}

Expand All @@ -80,7 +77,7 @@ public void error(ExtensionError extensionError) {
* If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the
* eventuality of any error that occurred while getting the Experience Cloud ID
*/
public static void getExperienceCloudId(final AdobeCallback<String> callback) {
public static void getExperienceCloudId(@NonNull final AdobeCallback<String> callback) {
if (callback == null) {
Log.debug(LOG_TAG, LOG_SOURCE, "Unexpected null callback, provide a callback to retrieve current ECID.");
return;
Expand All @@ -95,7 +92,7 @@ public static void getExperienceCloudId(final AdobeCallback<String> callback) {

final AdobeCallbackWithError<Event> callbackWithError = new AdobeCallbackWithError<Event>() {
@Override
public void call(Event responseEvent) {
public void call(final Event responseEvent) {
if (responseEvent == null || responseEvent.getEventData() == null) {
returnError(callback, AdobeError.UNEXPECTED_ERROR);
return;
Expand Down Expand Up @@ -125,7 +122,7 @@ public void call(Event responseEvent) {
}

@Override
public void fail(AdobeError adobeError) {
public void fail(final AdobeError adobeError) {
returnError(callback, adobeError);
Log.debug(
LOG_TAG,
Expand Down Expand Up @@ -159,7 +156,7 @@ public void fail(AdobeError adobeError) {
* If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the
* eventuality of any error that occurred while getting the identifiers query string
*/
public static void getUrlVariables(final AdobeCallback<String> callback) {
public static void getUrlVariables(@NonNull final AdobeCallback<String> callback) {
if (callback == null) {
Log.debug(
LOG_TAG,
Expand Down Expand Up @@ -231,7 +228,7 @@ public void fail(final AdobeError adobeError) {
*
* @param identityMap The identifiers to add or update.
*/
public static void updateIdentities(final IdentityMap identityMap) {
public static void updateIdentities(@NonNull final IdentityMap identityMap) {
if (identityMap == null || identityMap.isEmpty()) {
Log.debug(LOG_TAG, LOG_SOURCE, "Unable to updateIdentities, IdentityMap is null or empty");
return;
Expand All @@ -255,7 +252,7 @@ public static void updateIdentities(final IdentityMap identityMap) {
* @param item the {@link IdentityItem} to remove.
* @param namespace The namespace of the identity to remove.
*/
public static void removeIdentity(final IdentityItem item, final String namespace) {
public static void removeIdentity(@NonNull final IdentityItem item, @NonNull final String namespace) {
if (StringUtils.isNullOrEmpty(namespace)) {
Log.debug(LOG_TAG, LOG_SOURCE, "Unable to removeIdentity, namespace is null or empty");
return;
Expand Down Expand Up @@ -286,7 +283,7 @@ public static void removeIdentity(final IdentityItem item, final String namespac
* If an {@link AdobeCallbackWithError} is provided, an {@link AdobeError} can be returned in the
* eventuality of any error that occurred while getting the stored identities.
*/
public static void getIdentities(final AdobeCallback<IdentityMap> callback) {
public static void getIdentities(@NonNull final AdobeCallback<IdentityMap> callback) {
if (callback == null) {
Log.debug(
LOG_TAG,
Expand Down
Loading