Skip to content

Commit

Permalink
Add unit tests to cover missing branches
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeklim committed Oct 4, 2018
1 parent 975f53d commit 2657035
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,29 +155,37 @@ public void setDouble() {
assertEquals(0, properties.getProperties().size());

/* NaN value. */
double positiveInfinityValue = Double.NaN;
double nanValue = Double.NaN;
properties = new EventProperties();
properties.set(key, positiveInfinityValue);
properties.set(key, nanValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(1));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());

/* NaN value. */
double negativeInfinityValue = Double.NaN;
/* Positive infinity value. */
double positiveInfinityValue = Double.POSITIVE_INFINITY;
properties = new EventProperties();
properties.set(key, negativeInfinityValue);
properties.set(key, positiveInfinityValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(2));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());

/* Negative infinity value. */
double negativeInfinityValue = Double.NEGATIVE_INFINITY;
properties = new EventProperties();
properties.set(key, negativeInfinityValue);
assertEquals(0, properties.getProperties().size());
verifyStatic(times(3));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());

/* Normal value. */
double normalValue = 0.0;
properties.set(key, normalValue);
assertEquals(1, properties.getProperties().size());
DoubleTypedProperty expected = new DoubleTypedProperty();
expected.setName(key);
expected.setValue(normalValue);
verifyStatic(times(2));
verifyStatic(times(3));
AppCenterLog.error(eq(Analytics.LOG_TAG), anyString());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.appcenter.analytics.channel;

import com.microsoft.appcenter.analytics.ingestion.models.EventLog;
import com.microsoft.appcenter.ingestion.models.properties.BooleanTypedProperty;
import com.microsoft.appcenter.ingestion.models.properties.DoubleTypedProperty;
import com.microsoft.appcenter.ingestion.models.properties.StringTypedProperty;
import com.microsoft.appcenter.ingestion.models.properties.TypedProperty;
Expand Down Expand Up @@ -135,8 +136,27 @@ public void shouldFilterTooLongStringTypedProperty() {
assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
assertEquals(validEventName, mEventLog.getName());
assertEquals(1, mEventLog.getTypedProperties().size());
StringTypedProperty stringProperty = (StringTypedProperty)mEventLog.getTypedProperties().iterator().next();
StringTypedProperty stringProperty = (StringTypedProperty) mEventLog.getTypedProperties().iterator().next();
assertEquals(MAX_PROPERTY_ITEM_LENGTH, stringProperty.getName().length());
assertEquals(MAX_PROPERTY_ITEM_LENGTH, stringProperty.getValue().length());
}

/**
* This test case only makes up missing branch in validateProperties when TypedProperty isn't StringTypedProperty.
*/
@Test
public void shouldNotFilterNonStringTypedProperty() {
String validEventName = "eventName";
mEventLog.setName(validEventName);
BooleanTypedProperty property = new BooleanTypedProperty();
property.setName("name");
property.setValue(true);
mEventLog.setTypedProperties(Collections.<TypedProperty>singletonList(property));
assertFalse(mAnalyticsValidator.shouldFilter(mEventLog));
assertEquals(validEventName, mEventLog.getName());
assertEquals(1, mEventLog.getTypedProperties().size());
BooleanTypedProperty booleanProperty = (BooleanTypedProperty) mEventLog.getTypedProperties().iterator().next();
assertEquals("name", booleanProperty.getName());
assertTrue(booleanProperty.getValue());
}
}

0 comments on commit 2657035

Please sign in to comment.