Search in sources :

Example 1 with TemplateNumberFormat

use of freemarker.core.TemplateNumberFormat in project robozonky by RoboZonky.

the class InterestNumberFormatFactoryTest method formal.

@Test
void formal() throws TemplateValueFormatException {
    final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment());
    assertSoftly(softly -> {
        softly.assertThat(f.isLocaleBound()).isTrue();
        softly.assertThat(f.getDescription()).isNotNull().isNotEmpty();
        softly.assertThatThrownBy(() -> InterestNumberFormatFactory.INSTANCE.get("someparam", Locale.ENGLISH, Environment.getCurrentEnvironment())).isInstanceOf(InvalidFormatParametersException.class);
    });
}
Also used : TemplateNumberFormat(freemarker.core.TemplateNumberFormat) Test(org.junit.jupiter.api.Test)

Example 2 with TemplateNumberFormat

use of freemarker.core.TemplateNumberFormat in project robozonky by RoboZonky.

the class InterestNumberFormatFactoryTest method formattingCzech.

@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech() throws TemplateValueFormatException, TemplateModelException {
    final BigDecimal n = new BigDecimal("0.0001");
    final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment());
    final TemplateNumberModel m = () -> n;
    final String result = f.formatToPlainText(m);
    assertThat(result.trim()).isEqualTo("0,01" + (char) 160 + "%");
}
Also used : TemplateNumberFormat(freemarker.core.TemplateNumberFormat) TemplateNumberModel(freemarker.template.TemplateNumberModel) BigDecimal(java.math.BigDecimal) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Test(org.junit.jupiter.api.Test)

Example 3 with TemplateNumberFormat

use of freemarker.core.TemplateNumberFormat in project robozonky by RoboZonky.

the class InterestNumberFormatFactoryTest method formattingCzech2.

@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech2() throws TemplateValueFormatException, TemplateModelException {
    final BigDecimal n = new BigDecimal("0.0000");
    final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment());
    final TemplateNumberModel m = () -> n;
    final String result = f.formatToPlainText(m);
    assertThat(result.trim()).isEqualTo("0" + (char) 160 + "%");
}
Also used : TemplateNumberFormat(freemarker.core.TemplateNumberFormat) TemplateNumberModel(freemarker.template.TemplateNumberModel) BigDecimal(java.math.BigDecimal) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Test(org.junit.jupiter.api.Test)

Example 4 with TemplateNumberFormat

use of freemarker.core.TemplateNumberFormat in project robozonky by RoboZonky.

the class InterestNumberFormatFactoryTest method formattingCzech3.

@DisabledOnJre(JRE.JAVA_8)
@Test
void formattingCzech3() throws TemplateValueFormatException, TemplateModelException {
    final BigDecimal n = new BigDecimal("0.001");
    final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Defaults.LOCALE, Environment.getCurrentEnvironment());
    final TemplateNumberModel m = () -> n;
    final String result = f.formatToPlainText(m);
    assertThat(result.trim()).isEqualTo("0,1" + (char) 160 + "%");
}
Also used : TemplateNumberFormat(freemarker.core.TemplateNumberFormat) TemplateNumberModel(freemarker.template.TemplateNumberModel) BigDecimal(java.math.BigDecimal) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Test(org.junit.jupiter.api.Test)

Example 5 with TemplateNumberFormat

use of freemarker.core.TemplateNumberFormat in project robozonky by RoboZonky.

the class InterestNumberFormatFactoryTest method formattingEnglish.

@Test
void formattingEnglish() throws TemplateValueFormatException, TemplateModelException {
    final BigDecimal n = new BigDecimal("0.0001");
    final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment());
    final TemplateNumberModel m = () -> n;
    final Object result = f.formatToPlainText(m);
    assertThat(result).isEqualTo("0.01%");
}
Also used : TemplateNumberFormat(freemarker.core.TemplateNumberFormat) TemplateNumberModel(freemarker.template.TemplateNumberModel) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

TemplateNumberFormat (freemarker.core.TemplateNumberFormat)5 Test (org.junit.jupiter.api.Test)5 TemplateNumberModel (freemarker.template.TemplateNumberModel)4 BigDecimal (java.math.BigDecimal)4 DisabledOnJre (org.junit.jupiter.api.condition.DisabledOnJre)3