Add some tests

This commit is contained in:
James Agnew 2016-06-14 07:24:03 -05:00
parent aac914df22
commit dba470f8d6
3 changed files with 55 additions and 2 deletions

View File

@ -78,7 +78,7 @@ public class DecimalDt extends BasePrimitive<BigDecimal> implements Comparable<D
if (getValue() == null && theObj.getValue() == null) {
return 0;
}
if (getValue() != null && theObj.getValue() == null) {
if (getValue() != null && (theObj == null || theObj.getValue() == null)) {
return 1;
}
if (getValue() == null && theObj.getValue() != null) {

View File

@ -65,7 +65,7 @@ import ca.uhn.fhir.util.FhirTerser;
import ca.uhn.fhir.util.ParametersUtil;
import ca.uhn.fhir.util.ReflectionUtil;
class OperationParameter implements IParameter {
public class OperationParameter implements IParameter {
@SuppressWarnings("unchecked")
private static final Class<? extends IQueryParameterType>[] COMPOSITE_TYPES = new Class[0];

View File

@ -0,0 +1,53 @@
package ca.uhn.fhir.model.primitive;
import static org.junit.Assert.*;
import java.math.RoundingMode;
import org.junit.Test;
public class DecimalDtTest {
@Test
public void testRoundWithMode() {
DecimalDt dt = new DecimalDt("1.66666666");
dt.round(3, RoundingMode.FLOOR);
assertEquals("1.66", dt.getValueAsString());
}
@Test
public void testGetValue() {
DecimalDt dt = new DecimalDt("1.66666666");
assertEquals(1, dt.getValueAsInteger());
assertEquals("1.66666666", dt.getValueAsNumber().toString());
assertEquals("1.66666666", dt.getValueAsString());
}
@Test
public void testSetValue() {
DecimalDt dt = new DecimalDt();
dt.setValueAsInteger(123);
assertEquals("123", dt.getValueAsString());
}
@Test
public void testRound() {
DecimalDt dt = new DecimalDt("1.66666666");
dt.round(3);
assertEquals("1.67", dt.getValueAsString());
}
@Test
public void testCompareTo() {
DecimalDt dt = new DecimalDt("1.66666666");
assertEquals(1, dt.compareTo(null));
assertEquals(1, dt.compareTo(new DecimalDt()));
assertEquals(1, dt.compareTo(new DecimalDt("0.1")));
assertEquals(-1, dt.compareTo(new DecimalDt("99")));
assertEquals(0, dt.compareTo(new DecimalDt("1.66666666")));
assertEquals(0, new DecimalDt().compareTo(new DecimalDt()));
assertEquals(-1, new DecimalDt().compareTo(new DecimalDt("1.0")));
}
}