AdReport implements Serializable { @Override public String toString() { StringBuilder parameters = new StringBuilder(); appendKeyValue(parameters, "sdk_version", mSdkVersion); appendKeyValue(parameters, "creative_id", mAdResponse.getDspCreativeId()); appendKeyValue(parameters, "platform_version", Integer.toString(Build.VERSION.SDK_INT)); appendKeyValue(parameters, "device_model", mDeviceModel); appendKeyValue(parameters, "ad_unit_id", mAdUnitId); appendKeyValue(parameters, "device_locale", mDeviceLocale == null ? null : mDeviceLocale.toString()); appendKeyValue(parameters, "device_id", mUdid); appendKeyValue(parameters, "network_type", mAdResponse.getNetworkType()); appendKeyValue(parameters, "platform", "android"); appendKeyValue(parameters, "timestamp", getFormattedTimeStamp(mAdResponse.getTimestamp())); appendKeyValue(parameters, "ad_type", mAdResponse.getAdType()); Integer width = mAdResponse.getWidth(); Integer height = mAdResponse.getHeight(); appendKeyValue(parameters, "ad_size", "{" + (width == null ? "0" : width) + ", " + (height == null ? "0" : height) + "}"); return parameters.toString(); } AdReport(@NonNull String adUnitId, @NonNull ClientMetadata clientMetadata, @NonNull AdResponse adResponse); @Override String toString(); String getResponseString();  }
@Test public void testToString_shouldProperlyConstructParametersTextFile() throws Exception { String expectedParameters = "sdk_version : 1.15.2.2\n" + "creative_id : \n" + "platform_version : "+ Integer.toString(Build.VERSION.SDK_INT) +"\n" + "device_model : android\n" + "ad_unit_id : testAdUnit\n" + "device_locale : en_US\n" + "device_id : UDID\n" + "network_type : unknown\n" + "platform : android\n" + "timestamp : " + getCurrentDateTime() + "\n" + "ad_type : interstitial\n" + "ad_size : {480, 320}\n"; stub(mockClientMetadata.getSdkVersion()).toReturn("1.15.2.2"); stub(mockAdResponse.getDspCreativeId()).toReturn(""); stub(mockClientMetadata.getDeviceModel()).toReturn("android"); stub(mockClientMetadata.getDeviceLocale()).toReturn(Locale.US); stub(mockClientMetadata.getDeviceId()).toReturn("UDID"); stub(mockAdResponse.getNetworkType()).toReturn("unknown"); stub(mockAdResponse.getTimestamp()).toReturn(now.getTime()); stub(mockAdResponse.getAdType()).toReturn("interstitial"); stub(mockAdResponse.getWidth()).toReturn(480); stub(mockAdResponse.getHeight()).toReturn(320); subject = new AdReport("testAdUnit", mockClientMetadata, mockAdResponse); assertThat(subject.toString()).isEqualTo(expectedParameters); }
@Test public void constructor_shouldHandleInvalidAdConfigurationValues() throws Exception { String expectedParameters = "sdk_version : null\n" + "creative_id : null\n" + "platform_version : "+ Integer.toString(Build.VERSION.SDK_INT) +"\n" + "device_model : null\n" + "ad_unit_id : testAdUnit\n" + "device_locale : null\n" + "device_id : null\n" + "network_type : null\n" + "platform : android\n" + "timestamp : null" + "\n" + "ad_type : null\n" + "ad_size : {0, 0}\n"; stub(mockClientMetadata.getSdkVersion()).toReturn(null); stub(mockAdResponse.getDspCreativeId()).toReturn(null); stub(mockClientMetadata.getDeviceLocale()).toReturn(null); stub(mockClientMetadata.getDeviceId()).toReturn(null); stub(mockAdResponse.getNetworkType()).toReturn(null); stub(mockAdResponse.getTimestamp()).toReturn(-1L); stub(mockAdResponse.getAdType()).toReturn(null); stub(mockAdResponse.getWidth()).toReturn(null); stub(mockAdResponse.getHeight()).toReturn(null); subject = new AdReport("testAdUnit", mockClientMetadata, mockAdResponse); assertThat(subject.toString()).isEqualTo(expectedParameters); }