From 97b542aa654ccc4eb47b313de9078bdfabbe727b Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 1 Nov 2014 11:55:23 -0400 Subject: [PATCH] Relax BigDecimal equivalency checks --- src/test/java/com/iciql/test/SamplesTest.java | 3 ++- src/test/java/com/iciql/test/models/SupportedTypes.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/iciql/test/SamplesTest.java b/src/test/java/com/iciql/test/SamplesTest.java index df6d219..dbbf97f 100644 --- a/src/test/java/com/iciql/test/SamplesTest.java +++ b/src/test/java/com/iciql/test/SamplesTest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -214,7 +215,7 @@ public class SamplesTest { @Override public String toString() { - return customerId + ":" + orderId + ":" + total; + return customerId + ":" + orderId + ":" + new DecimalFormat("##.00").format(total); } } diff --git a/src/test/java/com/iciql/test/models/SupportedTypes.java b/src/test/java/com/iciql/test/models/SupportedTypes.java index 489650e..d9a6405 100644 --- a/src/test/java/com/iciql/test/models/SupportedTypes.java +++ b/src/test/java/com/iciql/test/models/SupportedTypes.java @@ -19,6 +19,7 @@ package com.iciql.test.models; import java.io.Serializable; import java.math.BigDecimal; +import java.math.MathContext; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -178,7 +179,10 @@ public class SupportedTypes implements Serializable { same &= same("myLong", myLong.equals(s.myLong)); same &= same("myFloat", IciqlSuite.equivalentTo(myFloat, s.myFloat)); same &= same("myDouble", IciqlSuite.equivalentTo(myDouble, s.myDouble)); - same &= same("myBigDecimal", myBigDecimal.compareTo(s.myBigDecimal) == 0); + + BigDecimal bda = myBigDecimal.round(MathContext.DECIMAL32); + BigDecimal bdb = s.myBigDecimal.round(MathContext.DECIMAL32); + same &= same("myBigDecimal", bda.compareTo(bdb) == 0); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); same &= same("myUtilDate", df.format(myUtilDate).equals(df.format(s.myUtilDate))); -- 2.39.5