Search in sources :

Example 1 with FormattedObject

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

the class FormattedObjectTest method testLocaleDependence.

@Test
public void testLocaleDependence() {
    final FormattedObject formattedObject = new FormattedObject(1.1234, "%.3f");
    assertEquals("wrong formatting", "1.123", formattedObject.toString());
    Locale.setDefault(new Locale("de"));
    // the format is evaluated only once
    assertEquals("no support for on-the-fly-changes of locale", "1.123", formattedObject.toString());
    // FormattedObject does not caches the formats
    assertEquals("formatting should be locale dependent", "1,123", new FormattedObject(1.1234, "%.3f").toString());
}
Also used : Locale(java.util.Locale) FormattedObject(org.freeplane.features.format.FormattedObject) Test(org.junit.Test)

Example 2 with FormattedObject

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

the class FormattedObjectTest method testSerializeNumber.

@Test
public void testSerializeNumber() {
    double number = 1.123456;
    final FormattedObject formattedObject = new FormattedObject(number, "#.##");
    final String serialized = "java.lang.Double|1.123456|number:decimal:#.##";
    assertEquals(serialized, FormattedObject.serialize(formattedObject));
    assertEquals("failure in deserialization", formattedObject, FormattedObject.deserialize(serialized));
}
Also used : FormattedObject(org.freeplane.features.format.FormattedObject) Test(org.junit.Test)

Example 3 with FormattedObject

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

the class FormattedObjectTest method testNestedIFormattedObject.

@Test
public void testNestedIFormattedObject() {
    double number = 1.123456;
    final FormattedNumber formattedNumber = new FormattedNumber(number, "#.##");
    final FormattedObject formattedObject = new FormattedObject(formattedNumber, "x: %s");
    assertEquals("wrong pattern", "x: %s", formattedObject.getPattern());
    assertEquals("wrong formatting", "x: 1.12", formattedObject.toString());
}
Also used : FormattedObject(org.freeplane.features.format.FormattedObject) FormattedNumber(org.freeplane.features.format.FormattedNumber) Test(org.junit.Test)

Example 4 with FormattedObject

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

the class FormattedObjectTest method testSerializeString.

@Test
public void testSerializeString() {
    String unformattedString = "\"sdf\"|sdf|sdf|: %s";
    final FormattedObject formattedObject = new FormattedObject(unformattedString, "|\"x\"|: %s");
    final String serialized = ""sdf"|sdf|sdf|: %s|string:formatter:|"x"|: %s";
    assertEquals(serialized, FormattedObject.serialize(formattedObject));
    assertEquals("failure in deserialization", formattedObject, FormattedObject.deserialize(serialized));
}
Also used : FormattedObject(org.freeplane.features.format.FormattedObject) Test(org.junit.Test)

Example 5 with FormattedObject

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

the class FormattedObjectTest method testStrangeInput.

@Test
public void testStrangeInput() {
    final FormattedDate date = new FormattedDate(new Date(), "yyyy-mm-dd");
    final FormattedObject formattedObject = new FormattedObject(date, "#.##");
    assertEquals("decimal format is not applicable to date", date.toString(), formattedObject.toString());
}
Also used : FormattedDate(org.freeplane.features.format.FormattedDate) FormattedObject(org.freeplane.features.format.FormattedObject) FormattedDate(org.freeplane.features.format.FormattedDate) Date(java.util.Date) Test(org.junit.Test)

Aggregations

FormattedObject (org.freeplane.features.format.FormattedObject)6 Test (org.junit.Test)5 Date (java.util.Date)1 Locale (java.util.Locale)1 FormattedDate (org.freeplane.features.format.FormattedDate)1 FormattedFormula (org.freeplane.features.format.FormattedFormula)1 FormattedNumber (org.freeplane.features.format.FormattedNumber)1 ExecuteScriptException (org.freeplane.plugin.script.ExecuteScriptException)1