### Question:
Quantities { public static QuantitativeAmount convert( QuantitativeAmount quantity, UnitName unitName ) throws UnitException{ if( quantity.getUnitName().equals(unitName)) return quantity; if( !quantity.getUnitName().compatible(unitName) ) throw new UnitException("Uncompatible units : " + quantity.getUnitName() + " vs " + unitName); UnitSet us = UnitSetRegistery.getUnitSet(unitName.getUnitSet()); if( us == null ) throw new UnitException("Unknown UnitSet : " + quantity.getUnitName().getUnitSet()); BigDecimal[] factors = us.getFactors(quantity.getUnitName(), unitName); return of( quantity.getAmount().multiply(factors[0]).divide(factors[1], us.getMathContext()), unitName); }  static QuantitativeAmount of( BigDecimal amount, Unit unit ); static QuantitativeAmount of( BigDecimal amount, UnitName unitName ); static QuantitativeAmount of( BigDecimal amount, String unitName ); static QuantitativeAmount convert( QuantitativeAmount quantity, UnitName unitName ); static QuantitativeAmount add( QuantitativeAmount x, BigDecimal amount ); static QuantitativeAmount add( QuantitativeAmount x, QuantitativeAmount y ); static QuantitativeAmount add( QuantitativeAmount x, QuantitativeAmount y, UnitName unitName ); static QuantitativeAmount subtract( QuantitativeAmount x, BigDecimal amount ); static QuantitativeAmount subtract( QuantitativeAmount x, QuantitativeAmount y ); static QuantitativeAmount subtract( QuantitativeAmount x, QuantitativeAmount y, UnitName unitName ); static QuantitativeAmount multiply( QuantitativeAmount x, BigDecimal amount ); static QuantitativeAmount multiply( QuantitativeAmount x, QuantitativeAmount y ); static QuantitativeAmount multiply( QuantitativeAmount x, QuantitativeAmount y, UnitName unitName ); static QuantitativeAmount divide( QuantitativeAmount base, BigDecimal amount ); static QuantitativeAmount divide( QuantitativeAmount x, QuantitativeAmount y ); static QuantitativeAmount divide( QuantitativeAmount x, QuantitativeAmount y, UnitName unitName );  }### Answer:
@Test public void testConvert() throws UnitException { System.out.println("convert"); QuantitativeAmount q = new QuantitativeAmount(BigDecimal.TEN, MassUnitSet.GRAM); QuantitativeAmount expResult = new QuantitativeAmount(BigDecimal.TEN, MassUnitSet.GRAM); QuantitativeAmount result = Quantities.convert(q, MassUnitSet.GRAM); assertEquals(expResult, result); }
@Test public void testConvert2() throws UnitException { System.out.println("convert2"); QuantitativeAmount q = new QuantitativeAmount(BigDecimal.TEN, MassUnitSet.GRAM); QuantitativeAmount expResult = new QuantitativeAmount( new BigDecimal(100), MassUnitSet.DECIGRAM); QuantitativeAmount result = Quantities.convert(q, MassUnitSet.DECIGRAM); assertEquals(expResult, result); }