@Test(expected = UnsupportedUnitConversionException.class) public final void shouldThrowExceptionIfConversionDoesNotExists() { possibleUnitConversionsImpl.convertTo(BigDecimal.ONE, "kg"); }
@Override public BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo) { final BigDecimal ratio = targetUnitToFactor.get(unitTo); if (ratio == null) { throw new UnsupportedUnitConversionException(unitFrom, unitTo); } BigDecimal convertedValue = quantityFrom.multiply(ratio); boolean unitIsInteger = targetUnitToIsInteger.computeIfAbsent(unitTo, dictionaryService::checkIfUnitIsInteger); if (unitIsInteger) { return numberService.setScaleWithDefaultMathContext(numberService.setScaleWithDefaultMathContext(convertedValue, 0)); } else { return numberService.setScaleWithDefaultMathContext(convertedValue); } }
PossibleUnitConversionsImpl implements InternalPossibleUnitConversions { @Override public BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo) { final BigDecimal ratio = targetUnitToFactor.get(unitTo); if (ratio == null) { throw new UnsupportedUnitConversionException(unitFrom, unitTo); } BigDecimal convertedValue = quantityFrom.multiply(ratio); boolean unitIsInteger = targetUnitToIsInteger.computeIfAbsent(unitTo, dictionaryService::checkIfUnitIsInteger); if (unitIsInteger) { return numberService.setScaleWithDefaultMathContext(numberService.setScaleWithDefaultMathContext(convertedValue, 0)); } else { return numberService.setScaleWithDefaultMathContext(convertedValue); } } }
PossibleUnitConversionsImpl implements InternalPossibleUnitConversions { @Override public BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo) { final BigDecimal ratio = targetUnitToFactor.get(unitTo); if (ratio == null) { throw new UnsupportedUnitConversionException(unitFrom, unitTo); } BigDecimal convertedValue = quantityFrom.multiply(ratio); boolean unitIsInteger = targetUnitToIsInteger.computeIfAbsent(unitTo, dictionaryService::checkIfUnitIsInteger); if (unitIsInteger) { return numberService.setScaleWithDefaultMathContext(numberService.setScaleWithDefaultMathContext(convertedValue, 0)); } else { return numberService.setScaleWithDefaultMathContext(convertedValue); } } PossibleUnitConversionsImpl(final String unitFrom, final NumberService numberService,
            final DataDefinition unitConversionItemDD, DictionaryService dictionaryService); }
PossibleUnitConversionsImpl implements InternalPossibleUnitConversions { @Override public BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo) { final BigDecimal ratio = targetUnitToFactor.get(unitTo); if (ratio == null) { throw new UnsupportedUnitConversionException(unitFrom, unitTo); } BigDecimal convertedValue = quantityFrom.multiply(ratio); boolean unitIsInteger = targetUnitToIsInteger.computeIfAbsent(unitTo, dictionaryService::checkIfUnitIsInteger); if (unitIsInteger) { return numberService.setScaleWithDefaultMathContext(numberService.setScaleWithDefaultMathContext(convertedValue, 0)); } else { return numberService.setScaleWithDefaultMathContext(convertedValue); } } PossibleUnitConversionsImpl(final String unitFrom, final NumberService numberService,
            final DataDefinition unitConversionItemDD, DictionaryService dictionaryService); @Override void addConversion(final UnitConversion unitConversion); @Override boolean isEmpty(); @Override boolean isDefinedFor(final String unit); @Override Set<String> getSupportedUnits(); @Override BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo); @Override BigDecimal convertTo(BigDecimal quantityFrom, String unitTo, int roundMode); @Override String getUnitFrom(); @Override Map<String, BigDecimal> asUnitToConversionMap(); @Override List<Entity> asEntities(final String ownerFieldName, final Entity ownerEntity); }
PossibleUnitConversionsImpl implements InternalPossibleUnitConversions { @Override public BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo) { final BigDecimal ratio = targetUnitToFactor.get(unitTo); if (ratio == null) { throw new UnsupportedUnitConversionException(unitFrom, unitTo); } BigDecimal convertedValue = quantityFrom.multiply(ratio); boolean unitIsInteger = targetUnitToIsInteger.computeIfAbsent(unitTo, dictionaryService::checkIfUnitIsInteger); if (unitIsInteger) { return numberService.setScaleWithDefaultMathContext(numberService.setScaleWithDefaultMathContext(convertedValue, 0)); } else { return numberService.setScaleWithDefaultMathContext(convertedValue); } } PossibleUnitConversionsImpl(final String unitFrom, final NumberService numberService,
            final DataDefinition unitConversionItemDD, DictionaryService dictionaryService); @Override void addConversion(final UnitConversion unitConversion); @Override boolean isEmpty(); @Override boolean isDefinedFor(final String unit); @Override Set<String> getSupportedUnits(); @Override BigDecimal convertTo(final BigDecimal quantityFrom, final String unitTo); @Override BigDecimal convertTo(BigDecimal quantityFrom, String unitTo, int roundMode); @Override String getUnitFrom(); @Override Map<String, BigDecimal> asUnitToConversionMap(); @Override List<Entity> asEntities(final String ownerFieldName, final Entity ownerEntity);  }