Skip to content

Commit 064aec9

Browse files
runnerrunner
authored andcommitted
Release 4.2.0
1 parent bec9f80 commit 064aec9

File tree

83 files changed

+1584
-482
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1584
-482
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Unity Advertisements copyright © 2021 Unity Technologies.
1+
Unity Advertisements copyright © 2022 Unity Technologies.
22
This software is subject to, and made available under, the terms of service for Operate Solutions (see https://unity3d.com/legal/one-operate-services-terms-of-service), and is an "Operate Service" as defined therein.
33

44
Your use of the Services constitutes your acceptance of such terms. Unless expressly provided otherwise, the software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the terms of service for details on these and other terms and conditions.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.unity3d.ads.example"
88
minSdkVersion 19
99
targetSdkVersion 30
10-
versionCode = 4100
11-
versionName = "4.1.0"
10+
versionCode = 4200
11+
versionName = "4.2.0"
1212
}
1313

1414
buildTypes {

unity-ads/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ if (project.rootProject.file('local.properties').exists()) {
1010
ext {
1111
GROUP_ID = "com.unity3d.ads"
1212
ARTIFACT_ID = "unity-ads"
13-
VERSION_ID = "4.1.0"
14-
VERSION_CODE = 4100
13+
VERSION_ID = "4.2.0"
14+
VERSION_CODE = 4200
1515
SIGN_AAR = properties.getProperty("SIGN_AAR") ?: false
1616
}
1717

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.unity3d.ads.test.instrumentation.services.ads.gmascar.handlers;
2+
3+
import com.unity3d.scar.adapter.common.GMAEvent;
4+
import com.unity3d.scar.adapter.common.scarads.ScarAdMetadata;
5+
import com.unity3d.services.ads.gmascar.handlers.ScarInterstitialAdHandler;
6+
import com.unity3d.services.core.misc.EventSubject;
7+
import com.unity3d.services.core.misc.IEventListener;
8+
import com.unity3d.services.core.webview.WebViewApp;
9+
import com.unity3d.services.core.webview.WebViewEventCategory;
10+
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
import org.mockito.Mock;
15+
import org.mockito.Mockito;
16+
import org.mockito.junit.MockitoJUnitRunner;
17+
18+
import static org.mockito.ArgumentMatchers.eq;
19+
import static org.mockito.Mockito.times;
20+
21+
@RunWith(MockitoJUnitRunner.class)
22+
public class ScarInterstitialAdHandlerTest {
23+
24+
@Mock
25+
WebViewApp mockWebViewApp;
26+
27+
@Mock
28+
EventSubject mockEventSubject;
29+
30+
@Before
31+
public void setup() {
32+
WebViewApp.setCurrentApp(mockWebViewApp);
33+
}
34+
35+
@Test
36+
public void testOnAdLoaded() {
37+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
38+
adHandler.onAdLoaded();
39+
40+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.AD_LOADED), eq("test-placementId"), eq("test-queryId"));
41+
}
42+
43+
@Test
44+
public void testOnAdFailedToLoad() {
45+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
46+
adHandler.onAdFailedToLoad(0, "Ad failed to load");
47+
48+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.LOAD_ERROR), eq("test-placementId"), eq("test-queryId"), eq("Ad failed to load"), eq(0));
49+
}
50+
51+
@Test
52+
public void testOnAdOpened() {
53+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
54+
adHandler.onAdOpened();
55+
56+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_STARTED);
57+
Mockito.verify(mockEventSubject, times(1)).subscribe(Mockito.<IEventListener>any());
58+
}
59+
60+
@Test
61+
public void testOnAdFailedToShow() {
62+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
63+
adHandler.onAdFailedToShow(0, "Ad failed to show");
64+
65+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.INTERSTITIAL_SHOW_ERROR), eq("test-placementId"), eq("test-queryId"), eq("Ad failed to show"), eq(0));
66+
}
67+
68+
@Test
69+
public void testOnAdSkipped() {
70+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
71+
Mockito.when(mockEventSubject.eventQueueIsEmpty()).thenReturn(false);
72+
adHandler.onAdClosed();
73+
74+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_SKIPPED);
75+
}
76+
77+
@Test
78+
public void testOnAdClosed() {
79+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
80+
adHandler.onAdClosed();
81+
82+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_CLOSED);
83+
Mockito.verify(mockEventSubject, times(1)).unsubscribe();
84+
}
85+
86+
@Test
87+
public void testOnAdImpression() {
88+
ScarInterstitialAdHandler adHandler = new ScarInterstitialAdHandler(getDefaultScarMeta(), mockEventSubject);
89+
adHandler.onAdImpression();
90+
91+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.INTERSTITIAL_IMPRESSION_RECORDED);
92+
}
93+
94+
private ScarAdMetadata getDefaultScarMeta() {
95+
return new ScarAdMetadata("test-placementId", "test-queryId", "test-adUnitId", "test-scarAdString", 30000);
96+
}
97+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.unity3d.ads.test.instrumentation.services.ads.gmascar.handlers;
2+
3+
import com.unity3d.scar.adapter.common.GMAEvent;
4+
import com.unity3d.scar.adapter.common.scarads.ScarAdMetadata;
5+
import com.unity3d.services.ads.gmascar.handlers.ScarRewardedAdHandler;
6+
import com.unity3d.services.core.misc.EventSubject;
7+
import com.unity3d.services.core.misc.IEventListener;
8+
import com.unity3d.services.core.webview.WebViewApp;
9+
import com.unity3d.services.core.webview.WebViewEventCategory;
10+
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
import org.mockito.Mock;
15+
import org.mockito.Mockito;
16+
import org.mockito.junit.MockitoJUnitRunner;
17+
18+
import static org.mockito.ArgumentMatchers.eq;
19+
import static org.mockito.Mockito.times;
20+
21+
@RunWith(MockitoJUnitRunner.class)
22+
public class ScarRewardedAdHandlerTest {
23+
24+
@Mock
25+
WebViewApp mockWebViewApp;
26+
27+
@Mock
28+
EventSubject mockEventSubject;
29+
30+
@Before
31+
public void setup() {
32+
WebViewApp.setCurrentApp(mockWebViewApp);
33+
}
34+
35+
@Test
36+
public void testOnAdLoaded() {
37+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
38+
adHandler.onAdLoaded();
39+
40+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.AD_LOADED), eq("test-placementId"), eq("test-queryId"));
41+
}
42+
43+
@Test
44+
public void testOnAdFailedToLoad() {
45+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
46+
adHandler.onAdFailedToLoad(0, "Ad failed to load");
47+
48+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.LOAD_ERROR), eq("test-placementId"), eq("test-queryId"), eq("Ad failed to load"), eq(0));
49+
}
50+
51+
@Test
52+
public void testOnAdOpened() {
53+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
54+
adHandler.onAdOpened();
55+
56+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_STARTED);
57+
Mockito.verify(mockEventSubject, times(1)).subscribe(Mockito.<IEventListener>any());
58+
}
59+
60+
@Test
61+
public void testOnAdFailedToShow() {
62+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
63+
adHandler.onAdFailedToShow(0, "Ad failed to show");
64+
65+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(eq(WebViewEventCategory.GMA), eq(GMAEvent.REWARDED_SHOW_ERROR), eq("test-placementId"), eq("test-queryId"), eq("Ad failed to show"), eq(0));
66+
}
67+
68+
@Test
69+
public void testOnAdSkipped() {
70+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
71+
adHandler.onAdClosed();
72+
73+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_SKIPPED);
74+
}
75+
76+
@Test
77+
public void testOnAdClosedAndRewardGranted() {
78+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
79+
adHandler.onUserEarnedReward();
80+
adHandler.onAdClosed();
81+
82+
Mockito.verify(mockWebViewApp, times(0)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_SKIPPED);
83+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.AD_CLOSED);
84+
Mockito.verify(mockEventSubject, times(1)).unsubscribe();
85+
}
86+
87+
@Test
88+
public void testOnAdImpression() {
89+
ScarRewardedAdHandler adHandler = new ScarRewardedAdHandler(getDefaultScarMeta(), mockEventSubject);
90+
adHandler.onAdImpression();
91+
92+
Mockito.verify(mockWebViewApp, times(1)).sendEvent(WebViewEventCategory.GMA, GMAEvent.REWARDED_IMPRESSION_RECORDED);
93+
}
94+
95+
private ScarAdMetadata getDefaultScarMeta() {
96+
return new ScarAdMetadata("test-placementId", "test-queryId", "test-adUnitId", "test-scarAdString", 30000);
97+
}
98+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.unity3d.ads.test.instrumentation.services.core.misc;
2+
3+
import com.unity3d.services.core.misc.EventSubject;
4+
import com.unity3d.services.core.misc.IEventListener;
5+
import com.unity3d.services.core.timer.IIntervalTimerFactory;
6+
import com.unity3d.services.core.timer.IIntervalTimerListener;
7+
import com.unity3d.services.core.timer.IntervalTimer;
8+
9+
import org.junit.Assert;
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.junit.runner.RunWith;
13+
import org.mockito.Mock;
14+
import org.mockito.Mockito;
15+
import org.mockito.junit.MockitoJUnitRunner;
16+
17+
import java.util.ArrayDeque;
18+
import java.util.Arrays;
19+
import java.util.Queue;
20+
import java.util.concurrent.ScheduledExecutorService;
21+
22+
import static org.mockito.Mockito.times;
23+
24+
@RunWith(MockitoJUnitRunner.class)
25+
public class EventSubjectTest<T> {
26+
27+
@Mock
28+
IntervalTimer mockIntervalTimer;
29+
30+
@Mock
31+
IIntervalTimerFactory mockTimerFactory;
32+
33+
@Mock
34+
IEventListener mockEventListener;
35+
36+
private String TEST_ACTIVITY_NAME = "com.test.activity";
37+
private Integer TEST_DURATION_MS = 1000;
38+
39+
@Before
40+
public void setup() {
41+
Mockito.when(mockTimerFactory.createTimer(Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt(), Mockito.<IIntervalTimerListener>any())).thenReturn(mockIntervalTimer);
42+
}
43+
44+
@Test
45+
public void testSubscribeWithEmptyEventQueue() {
46+
EventSubject<Integer> eventSubject = new EventSubject(TEST_ACTIVITY_NAME, new ArrayDeque<Integer>(), TEST_DURATION_MS, mockTimerFactory);
47+
eventSubject.subscribe(mockEventListener);
48+
Mockito.verify(mockIntervalTimer, times(0)).start(Mockito.<ScheduledExecutorService>any());
49+
}
50+
51+
@Test
52+
public void testSubscribeWithNullIntervalTimer() {
53+
Mockito.when(mockTimerFactory.createTimer(Mockito.anyString(), Mockito.anyInt(), Mockito.anyInt(), Mockito.<IIntervalTimerListener>any())).thenReturn(null);
54+
EventSubject<Integer> eventSubject = new EventSubject(TEST_ACTIVITY_NAME, new ArrayDeque<Integer>(), TEST_DURATION_MS, mockTimerFactory);
55+
eventSubject.subscribe(mockEventListener);
56+
Mockito.verify(mockIntervalTimer, times(0)).start(Mockito.<ScheduledExecutorService>any());
57+
}
58+
59+
@Test
60+
public void testSubscribeWithNullEventListener() {
61+
EventSubject<Integer> eventSubject = new EventSubject(TEST_ACTIVITY_NAME, new ArrayDeque<>(Arrays.asList(0, 1)), TEST_DURATION_MS, mockTimerFactory);
62+
eventSubject.subscribe(null);
63+
Mockito.verify(mockIntervalTimer, times(0)).start(Mockito.<ScheduledExecutorService>any());
64+
}
65+
66+
@Test
67+
public void testSubscribeAndEventQueueIsEmpty() {
68+
final Queue<Integer> testQueue = new ArrayDeque<>(Arrays.asList(0, 1));
69+
70+
EventSubject<Integer> eventSubject = new EventSubject(TEST_ACTIVITY_NAME, testQueue, TEST_DURATION_MS, mockTimerFactory);
71+
eventSubject.subscribe(mockEventListener);
72+
73+
int originalQueueSize = testQueue.size();
74+
for (int i = 0; i < originalQueueSize; i++) {
75+
eventSubject.sendNextEvent();
76+
Mockito.verify(mockEventListener, times(i+1)).onNextEvent(Mockito.any());
77+
Mockito.verify(mockIntervalTimer, times(i == originalQueueSize - 1 ? 1 : 0)).kill();
78+
Assert.assertEquals(testQueue.size(), originalQueueSize - i - 1);
79+
Assert.assertEquals(eventSubject.eventQueueIsEmpty(), i == originalQueueSize - 1 ? true : false);
80+
}
81+
}
82+
83+
@Test
84+
public void testUnsubscribe() {
85+
EventSubject<Integer> eventSubject = new EventSubject(TEST_ACTIVITY_NAME, new ArrayDeque<Integer>(), TEST_DURATION_MS, mockTimerFactory);
86+
eventSubject.unsubscribe();
87+
Mockito.verify(mockIntervalTimer, times(1)).kill();
88+
}
89+
}

0 commit comments

Comments
 (0)