NativeUrlGenerator extends AdUrlGenerator { @NonNull @Override public NativeUrlGenerator withAdUnitId(final String adUnitId) { mAdUnitId = adUnitId; return this; } NativeUrlGenerator(Context context); @NonNull @Override NativeUrlGenerator withAdUnitId(final String adUnitId); @Override String generateUrlString(final String serverHostname);  }
@Test public void generateUrlString_shouldNotIncludeDesiredAssetsIfNotSet() throws Exception { subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); List<String> desiredAssets = getDesiredAssetsListFromRequestUrlString(requestString); assertThat(desiredAssets.size()).isEqualTo(0); }
@Test public void generateUrlString_needsButDoesNotHaveReadPhoneState_shouldNotContainOperatorName() { shadowTelephonyManager.setNeedsReadPhoneState(true); shadowTelephonyManager.setReadPhoneStatePermission(false); shadowTelephonyManager.setNetworkOperatorName("TEST_CARRIER"); subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); assertThat(getNetworkOperatorNameFromRequestUrl(requestString)).isNullOrEmpty(); }
@Test public void generateUrlString_needsAndHasReadPhoneState_shouldContainOperatorName() { shadowTelephonyManager.setNeedsReadPhoneState(true); shadowTelephonyManager.setReadPhoneStatePermission(true); shadowTelephonyManager.setNetworkOperatorName("TEST_CARRIER"); subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); assertThat(getNetworkOperatorNameFromRequestUrl(requestString)).isEqualTo("TEST_CARRIER"); }
@Test public void generateUrlString_doesNotNeedReadPhoneState_shouldContainOperatorName() { shadowTelephonyManager.setNeedsReadPhoneState(false); shadowTelephonyManager.setReadPhoneStatePermission(false); shadowTelephonyManager.setNetworkOperatorName("TEST_CARRIER"); subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); assertThat(getNetworkOperatorNameFromRequestUrl(requestString)).isEqualTo("TEST_CARRIER"); }
@Test public void generateUrlString_withOnlyAdUnitSet_shouldReturnMinimumUrl() { subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); final String adUrl = generateMinimumUrlString(); assertThat(adUrl).isEqualTo( "http: AD_UNIT_ID + "&nsv=" + MoPub.SDK_VERSION + "&dn=unknown%2Cunknown%2Cunknown" + "&bundle=testBundle" + "&z=-0700" + "&o=u" + "&w=" + TEST_SCREEN_WIDTH + "&h=" + TEST_SCREEN_HEIGHT + "&sc_a=" + TEST_DENSITY + "&ct=3&av=1.0" + "&udid=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track"); }
@Test public void enableLocation_shouldIncludeLocationInUrl() { MoPub.setLocationAwareness(MoPub.LocationAwareness.NORMAL); subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); assertThat(getParameterFromRequestUrl(requestString, "ll")).isNotNull(); }
@Test public void disableLocation_shouldNotIncludeLocationInUrl() { MoPub.setLocationAwareness(MoPub.LocationAwareness.DISABLED); subject = new NativeUrlGenerator(context).withAdUnitId(AD_UNIT_ID); String requestString = generateMinimumUrlString(); assertThat(getParameterFromRequestUrl(requestString, "ll")).isNullOrEmpty(); }