@Test(expected = IllegalArgumentException.class) public void testWrongUnit() { SEVEN_HUNDRED_LITER.divide(ONE_KILO_GRAM); }
public BigDecimal divide(Quantity divisor) { if (!unit.equals(divisor.unit)) { throw new IllegalArgumentException("Can't mix two different units " + unit.name() + " and " + divisor.unit.name()); } return amount.multiply(scale.getBaseValue()).divide(divisor.amount).divide(divisor.scale.getBaseValue()); }
Quantity { public BigDecimal divide(Quantity divisor) { if (!unit.equals(divisor.unit)) { throw new IllegalArgumentException("Can't mix two different units " + unit.name() + " and " + divisor.unit.name()); } return amount.multiply(scale.getBaseValue()).divide(divisor.amount).divide(divisor.scale.getBaseValue()); } }
Quantity { public BigDecimal divide(Quantity divisor) { if (!unit.equals(divisor.unit)) { throw new IllegalArgumentException("Can't mix two different units " + unit.name() + " and " + divisor.unit.name()); } return amount.multiply(scale.getBaseValue()).divide(divisor.amount).divide(divisor.scale.getBaseValue()); } Quantity(BigDecimal amount);  Quantity(BigDecimal amount, Unit unit);  Quantity(BigDecimal amount, UnitScale scale, Unit unit); }
Quantity { public BigDecimal divide(Quantity divisor) { if (!unit.equals(divisor.unit)) { throw new IllegalArgumentException("Can't mix two different units " + unit.name() + " and " + divisor.unit.name()); } return amount.multiply(scale.getBaseValue()).divide(divisor.amount).divide(divisor.scale.getBaseValue()); } Quantity(BigDecimal amount);  Quantity(BigDecimal amount, Unit unit);  Quantity(BigDecimal amount, UnitScale scale, Unit unit); static Quantity getInstance(QuantityPO quantity); BigDecimal divide(Quantity divisor); @Override boolean equals(Object obj); BigDecimal getAmount(); UnitScale getScale(); BigDecimal getTrimmedAmount(); Unit getUnit(); @Override int hashCode(); QuantityPO toQuantityPO(); @Override String toString(); }
Quantity { public BigDecimal divide(Quantity divisor) { if (!unit.equals(divisor.unit)) { throw new IllegalArgumentException("Can't mix two different units " + unit.name() + " and " + divisor.unit.name()); } return amount.multiply(scale.getBaseValue()).divide(divisor.amount).divide(divisor.scale.getBaseValue()); } Quantity(BigDecimal amount);  Quantity(BigDecimal amount, Unit unit);  Quantity(BigDecimal amount, UnitScale scale, Unit unit); static Quantity getInstance(QuantityPO quantity); BigDecimal divide(Quantity divisor); @Override boolean equals(Object obj); BigDecimal getAmount(); UnitScale getScale(); BigDecimal getTrimmedAmount(); Unit getUnit(); @Override int hashCode(); QuantityPO toQuantityPO(); @Override String toString(); static final Quantity ONE_PCS; static final Quantity TEN_PCS; }