use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.
the class UnitFormatTest method testParseIrregularStringSimple.
@Test
public void testParseIrregularStringSimple() {
final UnitFormat format = SimpleUnitFormat.getInstance();
assertThrows(MeasurementParseException.class, () -> {
Unit<?> u = format.parse("bl//^--1a");
});
}
use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.
the class UnitFormatTest method testFormatLocal.
@Test
public void testFormatLocal() {
final UnitFormat format = LocalUnitFormat.getInstance();
final Appendable a = new StringBuilder();
try {
format.format(METRE, a);
} catch (IOException e) {
fail(e.getMessage());
}
assertEquals(METRE, sut.getUnit());
assertEquals("m", a.toString());
final Appendable a2 = new StringBuilder();
@SuppressWarnings("unchecked") Unit<Speed> v = (Unit<Speed>) METRE.divide(SECOND);
try {
format.format(v, a2);
} catch (IOException e) {
fail(e.getMessage());
}
assertEquals("m/s", a2.toString());
}
use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.
the class UnitFormatTest method testParseIrregularStringSimple.
@Test(expected = ParserException.class)
public void testParseIrregularStringSimple() {
final UnitFormat format = SimpleUnitFormat.getInstance();
Unit<?> u = format.parse("bl//^--1a");
}
use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.
the class UnitFormatTest method testFormatLocal.
@Test
public void testFormatLocal() {
final UnitFormat format = LocalUnitFormat.getInstance();
final Appendable a = new StringBuilder();
try {
format.format(METRE, a);
} catch (IOException e) {
fail(e.getMessage());
}
assertEquals(METRE, sut.getUnit());
assertEquals("m", a.toString());
final Appendable a2 = new StringBuilder();
@SuppressWarnings("unchecked") Unit<Speed> v = (Unit<Speed>) METRE.divide(SECOND);
try {
format.format(v, a2);
} catch (IOException e) {
fail(e.getMessage());
}
assertEquals("m/s", a2.toString());
}
use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.
the class LocalFormatTest method testFormatKm.
@Test
public void testFormatKm() {
final UnitFormat format = LocalUnitFormat.getInstance();
String s = format.format(KILO(METRE));
assertEquals("km", s);
}
Aggregations