Search in sources :

Example 6 with UnitFormat

use of javax.measure.format.UnitFormat in project indriya 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);
}
Also used : UnitFormat(javax.measure.format.UnitFormat) LocalUnitFormat(tech.units.indriya.format.LocalUnitFormat) Test(org.junit.jupiter.api.Test)

Example 7 with UnitFormat

use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.

the class UnitFormatTest method testParseLocal.

@Test
public void testParseLocal() {
    final UnitFormat format = LocalUnitFormat.getInstance();
    assertThrows(UnsupportedOperationException.class, () -> {
        try {
            Unit<?> u = format.parse("min");
            assertEquals("min", u.getSymbol());
        } catch (ParserException e) {
            fail(e.getMessage());
        }
    });
}
Also used : ParserException(javax.measure.format.ParserException) UnitFormat(javax.measure.format.UnitFormat) LocalUnitFormat(tech.units.indriya.format.LocalUnitFormat) SimpleUnitFormat(tech.units.indriya.format.SimpleUnitFormat) Test(org.junit.jupiter.api.Test)

Example 8 with UnitFormat

use of javax.measure.format.UnitFormat in project sis by apache.

the class UnitServicesTest method testGetUnitFormat.

/**
 * Tests {@link UnitServices#getUnitFormat(String)}.
 */
@Test
public void testGetUnitFormat() {
    final ServiceProvider provider = ServiceProvider.current();
    final UnitFormat f = provider.getUnitFormatService().getUnitFormat("name");
    ((org.apache.sis.measure.UnitFormat) f).setLocale(Locale.US);
    assertEquals("CUBIC_METRE", "cubic meter", f.format(Units.CUBIC_METRE));
}
Also used : UnitFormat(javax.measure.format.UnitFormat) ServiceProvider(javax.measure.spi.ServiceProvider) Test(org.junit.Test)

Example 9 with UnitFormat

use of javax.measure.format.UnitFormat in project unit-api by unitsofmeasurement.

the class UnitFormatTest method testMoreLocalSensitive.

@Test
public void testMoreLocalSensitive() {
    final UnitFormat simple = SimpleTestUnitFormat.getInstance();
    assertFalse(simple.isLocaleSensitive());
}
Also used : UnitFormat(javax.measure.format.UnitFormat) Test(org.junit.jupiter.api.Test)

Example 10 with UnitFormat

use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.

the class LocalFormatTest method testFormatMm.

@Test
public void testFormatMm() {
    final UnitFormat format = LocalUnitFormat.getInstance();
    String s = format.format(MILLI(METRE));
    assertEquals("mm", s);
}
Also used : UnitFormat(javax.measure.format.UnitFormat) LocalUnitFormat(tech.units.indriya.format.LocalUnitFormat) Test(org.junit.jupiter.api.Test)

Aggregations

UnitFormat (javax.measure.format.UnitFormat)17 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 LocalUnitFormat (tech.units.indriya.format.LocalUnitFormat)7 SimpleUnitFormat (tech.units.indriya.format.SimpleUnitFormat)3 IOException (java.io.IOException)2 Unit (javax.measure.Unit)2 ParserException (javax.measure.format.ParserException)2 Speed (javax.measure.quantity.Speed)2 Locale (java.util.Locale)1 ServiceProvider (javax.measure.spi.ServiceProvider)1 Ignore (org.junit.Ignore)1 Disabled (org.junit.jupiter.api.Disabled)1