use of javax.measure.Quantity in project indriya by unitsofmeasurement.
the class TimeQuantitiesTest method ofLocalTimeTemporalAdjustTest.
@Test
public void ofLocalTimeTemporalAdjustTest() {
LocalTime a = LocalTime.MIDNIGHT;
TemporalAdjuster temporalAdjuster = (temporal) -> temporal.plus(12L, ChronoUnit.HOURS);
Quantity<Time> time = TimeQuantities.getQuantity(a, () -> temporalAdjuster);
assertEquals(Integer.valueOf(12), Integer.valueOf(time.getValue().intValue()));
assertEquals(Units.HOUR, time.getUnit());
}
use of javax.measure.Quantity in project sis by apache.
the class QuantitiesTest method testCastOrCopy.
/**
* Tests {@link Quantities#castOrCopy(Quantity)}.
*/
@Test
public void testCastOrCopy() {
Quantity<Length> q = Quantities.create(5, Units.KILOMETRE);
assertSame(q, Quantities.castOrCopy(q));
q = new Quantity<Length>() {
@Override
public Number getValue() {
return 8;
}
@Override
public Unit<Length> getUnit() {
return Units.CENTIMETRE;
}
@Override
public Quantity<Length> add(Quantity<Length> ignored) {
return null;
}
@Override
public Quantity<Length> subtract(Quantity<Length> ignored) {
return null;
}
@Override
public Quantity<?> multiply(Quantity<?> ignored) {
return null;
}
@Override
public Quantity<?> divide(Quantity<?> ignored) {
return null;
}
@Override
public Quantity<Length> multiply(Number ignored) {
return null;
}
@Override
public Quantity<Length> divide(Number ignored) {
return null;
}
@Override
public Quantity<?> inverse() {
return null;
}
@Override
public Quantity<Length> to(Unit<Length> ignored) {
return null;
}
@Override
public <T extends Quantity<T>> Quantity<T> asType(Class<T> ignored) {
return null;
}
};
final Length c = Quantities.castOrCopy(q);
assertNotSame(q, c);
assertEquals("value", 8, c.getValue().doubleValue(), STRICT);
assertSame("unit", Units.CENTIMETRE, c.getUnit());
}
Aggregations