Search in sources :

Example 1 with WaterTank

use of com.baeldung.measurement.WaterTank in project tutorials by eugenp.

the class WaterTankTests method givenQuantity_whenGetUnitAndConvertValue_thenSuccess.

@Test
public void givenQuantity_whenGetUnitAndConvertValue_thenSuccess() {
    WaterTank waterTank = new WaterTank();
    waterTank.setCapacityMeasure(Quantities.getQuantity(9.2, LITRE));
    assertEquals(LITRE, waterTank.getCapacityMeasure().getUnit());
    Quantity<Volume> waterCapacity = waterTank.getCapacityMeasure();
    double volumeInLitre = waterCapacity.getValue().doubleValue();
    assertEquals(9.2, volumeInLitre, 0.0f);
    double volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(LITRE)).getValue().doubleValue();
    assertEquals(9200.0, volumeInMilliLitre, 0.0f);
    // compilation error
    // volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(KILOGRAM));
    Unit<Length> Kilometer = MetricPrefix.KILO(METRE);
// compilation error
// Unit<Length> Centimeter = MetricPrefix.CENTI(LITRE);
}
Also used : Volume(javax.measure.quantity.Volume) Length(javax.measure.quantity.Length) WaterTank(com.baeldung.measurement.WaterTank) Test(org.junit.Test)

Aggregations

WaterTank (com.baeldung.measurement.WaterTank)1 Length (javax.measure.quantity.Length)1 Volume (javax.measure.quantity.Volume)1 Test (org.junit.Test)1