Search in sources :

Example 6 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedNumberTest method testLocaleDependence.

@Test
public void testLocaleDependence() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number, "#.##");
    assertEquals("wrong formatting", "1.12", formattedNumber.toString());
    Locale.setDefault(new Locale("de"));
    // FormattedNumber evaluates the format only once
    assertEquals("no support for on-the-fly-changes of locale", "1.12", formattedNumber.toString());
    // FormattedNumber caches the formats and formats evaluate the locale only once
    assertEquals("no support for on-the-fly-changes of locale", "1.12", new FormattedNumber(number, "#.##").toString());
    // a new pattern - not cached
    assertEquals("formatting should be locale dependent", "1,12", new FormattedNumber(number, "#.00").toString());
}
Also used : Locale(java.util.Locale) FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Example 7 with FormattedNumber

use of org.freeplane.features.format.FormattedNumber in project freeplane by freeplane.

the class FormattedNumberTest method testCompareTo.

@Test
public void testCompareTo() {
    final FormattedNumber formattedNumberNull = new FormattedNumber(null);
    Double number1 = 1.123456;
    final FormattedNumber formattedNumber1 = new FormattedNumber(number1);
    Double number2 = 1.123457;
    final FormattedNumber formattedNumber2 = new FormattedNumber(number2);
    assertEquals(-1, number1.compareTo(number2));
    assertEquals(-1, formattedNumber1.compareTo(formattedNumber2));
    assertEquals(-1, formattedNumberNull.compareTo(formattedNumber2));
    assertEquals(1, formattedNumber1.compareTo(null));
    assertEquals(1, number2.compareTo(number1));
    assertEquals(1, formattedNumber2.compareTo(formattedNumber1));
    // NPE (OK - only limited support for nulls): assertEquals(1, formattedNumber2.compareTo(formattedNumberNull));
    assertEquals(-1, formattedNumberNull.compareTo(formattedNumber1));
}
Also used : FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Aggregations

FormattedNumber (org.freeplane.features.format.FormattedNumber)7 Test (org.junit.Test)6 Locale (java.util.Locale)1 FormattedDate (org.freeplane.features.format.FormattedDate)1 FormattedObject (org.freeplane.features.format.FormattedObject)1