BigDecimalExactClassTransformer implements TypeTransformer { @Override public Object transform(Object o) { if (o == null) { return null; } if (!(o instanceof java.math.BigDecimal)) { throw new UnsupportedOperationException(this.getClass().getSimpleName() + " cannot transform objects of type " + o.getClass().getName()); } return new java.math.BigDecimal(((java.math.BigDecimal) o).toString()); }  @Override Object transform(Object o);  }
@Test public void transformsBigDecimaltoBigDecimalTest() { BigDecimal bd = new BigDecimal(inBigDec.toString()); BigDecimal outBigDec = (BigDecimal) bdt.transform(bd); assertEquals(outBigDec, inBigDec); }
@Test public void transformsNormalisedBigDecimaltoBigDecimalTest() { NormalisedBigDecimal nbd = new NormalisedBigDecimal(inBigDec); BigDecimal outBigDec = (BigDecimal) bdt.transform(nbd); assertEquals(outBigDec, inBigDec); }
@Test public void rejectsNonBigDecimalInputTest() { Double notABigBecimal = 1.0; exception.expect(UnsupportedOperationException.class); exception.expectMessage("BigDecimalExactClassTransformer cannot transform objects of type java.lang.Double"); bdt.transform(notABigBecimal); }
@Test public void transformsToExactlyBigDecimalTest() { NormalisedBigDecimal nbd = new NormalisedBigDecimal(inBigDec); Object outBigDec = bdt.transform(nbd); assertEquals(outBigDec.getClass(), BigDecimal.class); }