Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #696: Corresctly handle negative numbers
- Loading branch information
1 parent
6aa58cf
commit 274e218
Showing
5 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/param/NumberParamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ca.uhn.fhir.rest.param; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.util.TestUtil; | ||
|
||
public class NumberParamTest { | ||
private static FhirContext ourCtx = FhirContext.forDstu3(); | ||
|
||
@Test | ||
public void testFull() { | ||
NumberParam p = new NumberParam(); | ||
p.setValueAsQueryToken(ourCtx, null, null, "<5.4"); | ||
assertEquals(ParamPrefixEnum.LESSTHAN, p.getPrefix()); | ||
assertEquals("5.4", p.getValue().toPlainString()); | ||
assertEquals("lt5.4", p.getValueAsQueryToken(ourCtx)); | ||
} | ||
|
||
@Test | ||
public void testApproximateLegacy() { | ||
NumberParam p = new NumberParam(); | ||
p.setValueAsQueryToken(ourCtx, null, null, "~5.4"); | ||
assertEquals(null,p.getComparator()); | ||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix()); | ||
assertEquals("5.4", p.getValue().toPlainString()); | ||
assertEquals("ap5.4", p.getValueAsQueryToken(ourCtx)); | ||
} | ||
|
||
@Test | ||
public void testApproximate() { | ||
NumberParam p = new NumberParam(); | ||
p.setValueAsQueryToken(ourCtx, null, null, "ap5.4"); | ||
assertEquals(null,p.getComparator()); | ||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix()); | ||
assertEquals("5.4", p.getValue().toPlainString()); | ||
assertEquals("ap5.4", p.getValueAsQueryToken(ourCtx)); | ||
} | ||
|
||
@Test | ||
public void testNoQualifier() { | ||
NumberParam p = new NumberParam(); | ||
p.setValueAsQueryToken(ourCtx, null, null, "5.4"); | ||
assertEquals(null, p.getComparator()); | ||
assertEquals(null, p.getPrefix()); | ||
assertEquals("5.4", p.getValue().toPlainString()); | ||
assertEquals("5.4", p.getValueAsQueryToken(ourCtx)); | ||
} | ||
|
||
|
||
/** | ||
* See #696 | ||
*/ | ||
@Test | ||
public void testNegativeNumber() { | ||
NumberParam p = new NumberParam(); | ||
p.setValueAsQueryToken(ourCtx, null, null, "-5.4"); | ||
assertEquals(null, p.getComparator()); | ||
assertEquals(null, p.getPrefix()); | ||
assertEquals("-5.4", p.getValue().toPlainString()); | ||
assertEquals(new BigDecimal("-5.4"), p.getValue()); | ||
assertEquals("-5.4", p.getValueAsQueryToken(ourCtx)); | ||
} | ||
|
||
|
||
@AfterClass | ||
public static void afterClassClearContext() { | ||
TestUtil.clearAllStaticFieldsForUnitTest(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters