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

Remove Powermock and fix unit and functional tests #78

Merged
Merged
2 changes: 1 addition & 1 deletion code/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ext {

// test dependencies
junitVersion = "1.1.3"
mockitoCoreVersion = "2.28.2"
mockitoCoreVersion = "4.5.1"
prudrabhat marked this conversation as resolved.
Show resolved Hide resolved
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

// spotless
Expand Down
13 changes: 6 additions & 7 deletions code/edgeidentity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,17 @@ dependencies {
testImplementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}"
testImplementation "org.mockito:mockito-core:${rootProject.ext.mockitoCoreVersion}"
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
testImplementation 'org.powermock:powermock-api-mockito2:2.0.0'
testImplementation 'org.powermock:powermock-module-junit4:2.0.0'
testImplementation 'org.json:json:20180813'

androidTestImplementation "androidx.test.ext:junit:${rootProject.ext.junitVersion}"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Using older version of PowerMock as it supports minimum Android API < 26
// the root issue appears to be a dependency with Objenesis in Mockito-Core
// where Objenesis 2 requires minimum Android API 26
androidTestImplementation 'org.powermock:powermock-module-junit4:1+'
androidTestImplementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
androidTestImplementation "com.adobe.marketing.mobile:identity:1.+"

// TODO: Uncomment next line when Identity 2.0 artifacts are published to maven
// implementation "com.adobe.marketing.mobile:identity:2.+"
androidTestImplementation ("com.github.adobe.aepsdk-core-android:identity:dev-v2.0.0-SNAPSHOT") {
transitive = false
}
}

tasks.withType(Test) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright 2022 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

package com.adobe.marketing.mobile;

/**
* Helper class that exists as a to access test helper methods provided in core
* within the package com.adobe.marketing.mobile
*/
public class MobileCoreHelper {

/**
* Wrapper around {@link MobileCore#resetSDK()}
*/
public static void resetSDK() {
MobileCore.resetSDK();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@

package com.adobe.marketing.mobile.edge.identity;

import static com.adobe.marketing.mobile.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.TestHelper.getXDMSharedStateFor;
import static com.adobe.marketing.mobile.edge.identity.IdentityAndroidTestUtil.createXDMIdentityMap;
import static com.adobe.marketing.mobile.edge.identity.IdentityAndroidTestUtil.flattenMap;
import static com.adobe.marketing.mobile.edge.identity.IdentityFunctionalTestUtil.registerEdgeIdentityExtension;
import static com.adobe.marketing.mobile.edge.identity.IdentityFunctionalTestUtil.setEdgeIdentityPersistence;
import static com.adobe.marketing.mobile.edge.identity.IdentityTestUtil.createXDMIdentityMap;
import static com.adobe.marketing.mobile.edge.identity.IdentityTestUtil.flattenMap;
import static com.adobe.marketing.mobile.edge.identity.util.TestHelper.getDispatchedEventsWith;
import static com.adobe.marketing.mobile.edge.identity.util.TestHelper.getXDMSharedStateFor;
import static org.junit.Assert.assertEquals;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.adobe.marketing.mobile.Event;
import com.adobe.marketing.mobile.ExtensionError;
import com.adobe.marketing.mobile.ExtensionErrorCallback;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.TestHelper;
import com.adobe.marketing.mobile.TestPersistenceHelper;
import com.adobe.marketing.mobile.edge.identity.util.TestHelper;
import com.adobe.marketing.mobile.edge.identity.util.TestPersistenceHelper;
import com.adobe.marketing.mobile.util.JSONUtils;
import com.adobe.marketing.mobile.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -51,10 +50,11 @@ public void testGenericIdentityRequest_whenValidAdId_thenNewValidAdId() throws E
String newAdId = "8d9ca5ff-7e74-44ac-bbcd-7aee7baf4f6c";
setEdgeIdentityPersistence(
createXDMIdentityMap(
new IdentityTestUtil.TestItem("ECID", "primaryECID"),
new IdentityTestUtil.TestItem("GAID", initialAdId)
new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID"),
new IdentityAndroidTestUtil.TestItem("GAID", initialAdId)
)
);

registerEdgeIdentityExtension();

MobileCore.setAdvertisingIdentifier(newAdId);
Expand All @@ -73,7 +73,7 @@ public void testGenericIdentityRequest_whenValidAdId_thenNewValidAdId() throws E
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, newAdId);
}

Expand All @@ -83,8 +83,8 @@ public void testGenericIdentityRequest_whenValidAdId_thenNonAdId() throws Except
String initialAdId = "fa181743-2520-4ebc-b125-626baf1e3db8";
setEdgeIdentityPersistence(
createXDMIdentityMap(
new IdentityTestUtil.TestItem("ECID", "primaryECID"),
new IdentityTestUtil.TestItem("GAID", initialAdId)
new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID"),
new IdentityAndroidTestUtil.TestItem("GAID", initialAdId)
)
);
registerEdgeIdentityExtension();
Expand All @@ -105,7 +105,7 @@ public void testGenericIdentityRequest_whenValidAdId_thenNonAdId() throws Except
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, initialAdId);
}

Expand All @@ -116,8 +116,8 @@ public void testGenericIdentityRequest_whenValidAdId_thenSameValidAdId() throws
String newAdId = "fa181743-2520-4ebc-b125-626baf1e3db8";
setEdgeIdentityPersistence(
createXDMIdentityMap(
new IdentityTestUtil.TestItem("ECID", "primaryECID"),
new IdentityTestUtil.TestItem("GAID", initialAdId)
new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID"),
new IdentityAndroidTestUtil.TestItem("GAID", initialAdId)
)
);
registerEdgeIdentityExtension();
Expand All @@ -137,7 +137,7 @@ public void testGenericIdentityRequest_whenValidAdId_thenSameValidAdId() throws
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, newAdId);
}

Expand All @@ -148,8 +148,8 @@ public void testGenericIdentityRequest_whenValidAdId_thenEmptyAdId() throws Exce
String newAdId = "";
setEdgeIdentityPersistence(
createXDMIdentityMap(
new IdentityTestUtil.TestItem("ECID", "primaryECID"),
new IdentityTestUtil.TestItem("GAID", initialAdId)
new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID"),
new IdentityAndroidTestUtil.TestItem("GAID", initialAdId)
)
);
registerEdgeIdentityExtension();
Expand All @@ -169,7 +169,7 @@ public void testGenericIdentityRequest_whenValidAdId_thenEmptyAdId() throws Exce
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, null);
}

Expand All @@ -180,8 +180,8 @@ public void testGenericIdentityRequest_whenValidAdId_thenAllZerosAdId() throws E
String newAdId = "00000000-0000-0000-0000-000000000000";
setEdgeIdentityPersistence(
createXDMIdentityMap(
new IdentityTestUtil.TestItem("ECID", "primaryECID"),
new IdentityTestUtil.TestItem("GAID", initialAdId)
new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID"),
new IdentityAndroidTestUtil.TestItem("GAID", initialAdId)
)
);
registerEdgeIdentityExtension();
Expand All @@ -201,15 +201,15 @@ public void testGenericIdentityRequest_whenValidAdId_thenAllZerosAdId() throws E
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, null);
}

@Test
public void testGenericIdentityRequest_whenNoAdId_thenNewValidAdId() throws Exception {
// Test
String newAdId = "8d9ca5ff-7e74-44ac-bbcd-7aee7baf4f6c";
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityTestUtil.TestItem("ECID", "primaryECID")));
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID")));
registerEdgeIdentityExtension();

MobileCore.setAdvertisingIdentifier(newAdId);
Expand All @@ -228,14 +228,14 @@ public void testGenericIdentityRequest_whenNoAdId_thenNewValidAdId() throws Exce
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, newAdId);
}

@Test
public void testGenericIdentityRequest_whenNoAdId_thenNonAdId() throws Exception {
// Test
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityTestUtil.TestItem("ECID", "primaryECID")));
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID")));
registerEdgeIdentityExtension();

dispatchGenericIdentityNonAdIdEvent();
Expand All @@ -254,15 +254,15 @@ public void testGenericIdentityRequest_whenNoAdId_thenNonAdId() throws Exception
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, null);
}

@Test
public void testGenericIdentityRequest_whenNoAdId_thenEmptyAdId() throws Exception {
// Test
String newAdId = "";
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityTestUtil.TestItem("ECID", "primaryECID")));
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID")));
registerEdgeIdentityExtension();

MobileCore.setAdvertisingIdentifier(newAdId);
Expand All @@ -280,15 +280,15 @@ public void testGenericIdentityRequest_whenNoAdId_thenEmptyAdId() throws Excepti
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, null);
}

@Test
public void testGenericIdentityRequest_whenNoAdId_thenAllZerosAdIdTwice() throws Exception {
// Test
String newAdId = "00000000-0000-0000-0000-000000000000";
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityTestUtil.TestItem("ECID", "primaryECID")));
setEdgeIdentityPersistence(createXDMIdentityMap(new IdentityAndroidTestUtil.TestItem("ECID", "primaryECID")));
registerEdgeIdentityExtension();

MobileCore.setAdvertisingIdentifier(newAdId);
Expand All @@ -306,7 +306,7 @@ public void testGenericIdentityRequest_whenNoAdId_thenAllZerosAdIdTwice() throws
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson)));
Map<String, String> persistedMap = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson)));
verifyFlatIdentityMap(persistedMap, null);

// Reset wildcard listener
Expand All @@ -327,12 +327,12 @@ public void testGenericIdentityRequest_whenNoAdId_thenAllZerosAdIdTwice() throws
IdentityConstants.DataStoreKey.DATASTORE_NAME,
IdentityConstants.DataStoreKey.IDENTITY_PROPERTIES
);
Map<String, String> persistedMap2 = flattenMap(IdentityTestUtil.toMap(new JSONObject(persistedJson2)));
Map<String, String> persistedMap2 = flattenMap(JSONUtils.toMap(new JSONObject(persistedJson2)));
verifyFlatIdentityMap(persistedMap2, null);
}

/**
* Verifies that the expected events from the {@link MobileCore#setAdvertisingIdentifier(String)} or {@link MobileCore#dispatchEvent(Event, ExtensionErrorCallback)}
* Verifies that the expected events from the {@link MobileCore#setAdvertisingIdentifier(String)} or {@link MobileCore#dispatchEvent(Event)}
* APIs are properly dispatched. Verifies:
* 1. Event type and source
* 2. Event data/properties as required for proper ad ID functionality
Expand All @@ -352,14 +352,14 @@ private void verifyDispatchedEvents(boolean isGenericIdentityEventAdIdEvent, Str
// Verify Generic Identity event
assertEquals(1, dispatchedGenericIdentityEvents.size());
Event genericIdentityEvent = dispatchedGenericIdentityEvents.get(0);
assertEquals(isGenericIdentityEventAdIdEvent ? true : false, EventUtils.isAdIdEvent(genericIdentityEvent));
assertEquals(isGenericIdentityEventAdIdEvent, EventUtils.isAdIdEvent(genericIdentityEvent));
// Verify Edge Consent event
List<Event> dispatchedConsentEvents = getDispatchedEventsWith(
IdentityConstants.EventType.EDGE_CONSENT,
IdentityConstants.EventSource.UPDATE_CONSENT
);
assertEquals(Utils.isNullOrEmpty(expectedConsentValue) ? 0 : 1, dispatchedConsentEvents.size());
if (!Utils.isNullOrEmpty(expectedConsentValue)) {
assertEquals(StringUtils.isNullOrEmpty(expectedConsentValue) ? 0 : 1, dispatchedConsentEvents.size());
if (!StringUtils.isNullOrEmpty(expectedConsentValue)) {
Map<String, String> consentDataMap = flattenMap(dispatchedConsentEvents.get(0).getEventData());
assertEquals("GAID", consentDataMap.get("consents.adID.idType"));
assertEquals(expectedConsentValue, consentDataMap.get("consents.adID.val"));
Expand Down Expand Up @@ -389,7 +389,6 @@ private void verifyFlatIdentityMap(
assertEquals("false", flatIdentityMap.get("identityMap.ECID[0].primary"));
assertEquals(expectedECID, flatIdentityMap.get("identityMap.ECID[0].id"));
assertEquals("ambiguous", flatIdentityMap.get("identityMap.ECID[0].authenticatedState"));
return;
}

/**
Expand All @@ -413,14 +412,6 @@ private void dispatchGenericIdentityNonAdIdEvent() {
}
)
.build();
MobileCore.dispatchEvent(
genericIdentityNonAdIdEvent,
new ExtensionErrorCallback<ExtensionError>() {
@Override
public void error(ExtensionError extensionError) {
Log.e("IdentityAdIdTest", "Failed to dispatch event." + extensionError.toString());
}
}
);
MobileCore.dispatchEvent(genericIdentityNonAdIdEvent);
}
}
Loading