-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
runner
authored and
runner
committed
Mar 21, 2022
1 parent
adcf7af
commit bec9f80
Showing
117 changed files
with
4,601 additions
and
277 deletions.
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
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
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
apply plugin: 'jacoco' | ||
|
||
jacoco { | ||
toolVersion = '0.8.1' | ||
toolVersion = '0.8.5' | ||
} | ||
|
||
tasks.withType(Test) { | ||
|
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
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
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
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
93 changes: 93 additions & 0 deletions
93
...ads/test/instrumentation/services/core/configuration/ConfigurationRequestFactoryTest.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,93 @@ | ||
package com.unity3d.ads.test.instrumentation.services.core.configuration; | ||
|
||
import com.unity3d.services.core.configuration.Configuration; | ||
import com.unity3d.services.core.configuration.ConfigurationRequestFactory; | ||
import com.unity3d.services.core.configuration.Experiments; | ||
import com.unity3d.services.core.device.reader.IDeviceInfoReader; | ||
import com.unity3d.services.core.request.WebRequest; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.net.MalformedURLException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ConfigurationRequestFactoryTest { | ||
|
||
@Mock | ||
Experiments _experimentsMock; | ||
|
||
@Mock | ||
Configuration _configurationMock; | ||
|
||
@Mock | ||
IDeviceInfoReader _deviceInfoReaderMock; | ||
|
||
static final String CONFIG_URL = "http://configurl/"; | ||
|
||
@Test | ||
public void testConfigurationRequestFactoryPost() throws MalformedURLException { | ||
Mockito.when(_experimentsMock.isTwoStageInitializationEnabled()).thenReturn(true); | ||
Mockito.when(_experimentsMock.isPOSTMethodInConfigRequestEnabled()).thenReturn(true); | ||
Mockito.when(_configurationMock.getExperiments()).thenReturn(_experimentsMock); | ||
|
||
ConfigurationRequestFactory configurationRequestFactory = new ConfigurationRequestFactory(_configurationMock, _deviceInfoReaderMock, CONFIG_URL); | ||
WebRequest webRequest = configurationRequestFactory.getWebRequest(); | ||
Assert.assertEquals("POST", webRequest.getRequestType()); | ||
Map<String, List<String>> headers = webRequest.getHeaders(); | ||
Assert.assertEquals("gzip", headers.get("Content-Encoding").get(0)); | ||
} | ||
|
||
@Test | ||
public void testConfigurationRequestFactoryGetIfTsiDisabled() throws MalformedURLException { | ||
Mockito.when(_experimentsMock.isTwoStageInitializationEnabled()).thenReturn(false); | ||
Mockito.when(_experimentsMock.isPOSTMethodInConfigRequestEnabled()).thenReturn(true); | ||
Mockito.when(_configurationMock.getExperiments()).thenReturn(_experimentsMock); | ||
|
||
ConfigurationRequestFactory configurationRequestFactory = new ConfigurationRequestFactory(_configurationMock, _deviceInfoReaderMock, CONFIG_URL); | ||
WebRequest webRequest = configurationRequestFactory.getWebRequest(); | ||
Assert.assertEquals("GET", webRequest.getRequestType()); | ||
Assert.assertTrue("ts missing from query", webRequest.getQuery().contains("ts")); | ||
Assert.assertTrue("sdkVersion missing from query", webRequest.getQuery().contains("sdkVersion")); | ||
Assert.assertTrue("sdkVersionName missing from query", webRequest.getQuery().contains("sdkVersionName")); | ||
Assert.assertTrue("gameId missing from query", webRequest.getQuery().contains("gameId")); | ||
} | ||
|
||
@Test | ||
public void testConfigurationRequestFactoryGetIfTsiEnabled() throws MalformedURLException { | ||
Mockito.when(_experimentsMock.isTwoStageInitializationEnabled()).thenReturn(true); | ||
Mockito.when(_experimentsMock.isPOSTMethodInConfigRequestEnabled()).thenReturn(false); | ||
Mockito.when(_configurationMock.getExperiments()).thenReturn(_experimentsMock); | ||
|
||
ConfigurationRequestFactory configurationRequestFactory = new ConfigurationRequestFactory(_configurationMock, _deviceInfoReaderMock, CONFIG_URL); | ||
WebRequest webRequest = configurationRequestFactory.getWebRequest(); | ||
Assert.assertEquals("GET", webRequest.getRequestType()); | ||
Assert.assertEquals("c=H4sIAAAAAAAAAKuuBQBDv6ajAgAAAA%3D%3D", webRequest.getQuery()); | ||
} | ||
|
||
@Test | ||
public void testConfigurationRequestFactoryGetIfPostDisabled() throws MalformedURLException { | ||
Mockito.when(_experimentsMock.isTwoStageInitializationEnabled()).thenReturn(true); | ||
Mockito.when(_experimentsMock.isPOSTMethodInConfigRequestEnabled()).thenReturn(false); | ||
Mockito.when(_configurationMock.getExperiments()).thenReturn(_experimentsMock); | ||
|
||
ConfigurationRequestFactory configurationRequestFactory = new ConfigurationRequestFactory(_configurationMock, _deviceInfoReaderMock, CONFIG_URL); | ||
WebRequest webRequest = configurationRequestFactory.getWebRequest(); | ||
Assert.assertEquals("GET", webRequest.getRequestType()); | ||
} | ||
|
||
@Test | ||
public void testConfigurationRequestFactoryGetNullExperiments() throws MalformedURLException { | ||
Mockito.when(_configurationMock.getExperiments()).thenReturn(null); | ||
|
||
ConfigurationRequestFactory configurationRequestFactory = new ConfigurationRequestFactory(_configurationMock, _deviceInfoReaderMock, CONFIG_URL); | ||
WebRequest webRequest = configurationRequestFactory.getWebRequest(); | ||
Assert.assertEquals("GET", webRequest.getRequestType()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ava/com/unity3d/ads/test/instrumentation/services/core/configuration/ExperimentsTest.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,59 @@ | ||
package com.unity3d.ads.test.instrumentation.services.core.configuration; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import com.unity3d.services.core.configuration.Experiments; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ExperimentsTest { | ||
|
||
@Test | ||
public void testExperimentsWithData() throws JSONException { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("fff", false); | ||
jsonObject.put("tsi", false); | ||
jsonObject.put("tsi_dc", true); | ||
jsonObject.put("tsi_epii", false); | ||
jsonObject.put("tsi_p", false); | ||
|
||
Experiments experiments = new Experiments(jsonObject); | ||
Assert.assertTrue(experiments.isHandleDeveloperConsent()); | ||
Assert.assertFalse(experiments.isTwoStageInitializationEnabled()); | ||
} | ||
|
||
@Test | ||
public void testExperimentsWithMissingData() throws JSONException { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("fff", false); | ||
|
||
Experiments experiments = new Experiments(jsonObject); | ||
Assert.assertFalse(experiments.isHandleDeveloperConsent()); | ||
} | ||
|
||
@Test | ||
public void testExperimentsWithEmptyData() { | ||
JSONObject jsonObject = new JSONObject(); | ||
|
||
Experiments experiments = new Experiments(jsonObject); | ||
Assert.assertFalse(experiments.isHandleDeveloperConsent()); | ||
} | ||
|
||
@Test | ||
public void testExperimentsWithNullData() { | ||
Experiments experiments = new Experiments(null); | ||
Assert.assertFalse(experiments.isHandleDeveloperConsent()); | ||
} | ||
|
||
@Test | ||
public void testExperimentsDefault() { | ||
Experiments experiments = new Experiments(); | ||
Assert.assertFalse(experiments.isHandleDeveloperConsent()); | ||
} | ||
|
||
} |
Oops, something went wrong.