Breaking test and fix
This commit is contained in:
parent
8851c35563
commit
f210ef36a5
|
@ -35,6 +35,7 @@ import java.math.BigDecimal;
|
|||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDecimalDatatype;
|
||||
|
||||
import ca.uhn.fhir.model.api.annotation.DatatypeDef;
|
||||
|
@ -166,8 +167,13 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
|
|||
}
|
||||
|
||||
public void setValueAsString(String theString) {
|
||||
setValue(new BigDecimal(theString));
|
||||
setRepresentation(theString);
|
||||
if (StringUtils.isBlank(theString)) {
|
||||
setValue((BigDecimal) null);
|
||||
setRepresentation(null);
|
||||
} else {
|
||||
setValue(new BigDecimal(theString));
|
||||
setRepresentation(theString);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -184,7 +190,7 @@ public class DecimalType extends PrimitiveType<BigDecimal> implements Comparable
|
|||
/**
|
||||
* A parser can provide a literal representation for the decimal value that preserves
|
||||
* the presented form.
|
||||
*
|
||||
* <p/>
|
||||
* All sorts of bad things can happen if this method is used to set the string representation
|
||||
* to anything other than what was parsed into the actual value. Don't do that
|
||||
*
|
||||
|
|
|
@ -3,9 +3,23 @@ package org.hl7.fhir.r5.model;
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class DecimalTypeNullTest {
|
||||
|
||||
public static Stream<Arguments> provideEmptyOrNullStringsConstructor() {
|
||||
return Stream.of(
|
||||
Arguments.of((String)null),
|
||||
Arguments.of(""),
|
||||
Arguments.of(" ")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test null value toString()")
|
||||
void testToString() {
|
||||
|
@ -44,4 +58,19 @@ class DecimalTypeNullTest {
|
|||
DecimalType copyDecimal = (DecimalType) nullDecimal.typedCopy();
|
||||
Assertions.assertNull(copyDecimal.getValue());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideEmptyOrNullStringsConstructor")
|
||||
void testNullValue(String theStringValue) {
|
||||
DecimalType nullDecimal = new DecimalType();
|
||||
Assertions.assertNull(nullDecimal.getValue());
|
||||
Assertions.assertNull(nullDecimal.asStringValue());
|
||||
|
||||
DecimalType anotherNullDecimal = new DecimalType(theStringValue);
|
||||
Assertions.assertNull(anotherNullDecimal.getValue());
|
||||
Assertions.assertNull(anotherNullDecimal.asStringValue());
|
||||
|
||||
Assertions.assertTrue(nullDecimal.equalsDeep(anotherNullDecimal));
|
||||
Assertions.assertTrue(nullDecimal.equalsShallow(anotherNullDecimal));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue