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 generateNativeAdUrl_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 generateNativeAdUrl_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 generateNativeAdUrl_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 generateNativeAdUrl_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"); }