InterestNumberFormatFactory extends TemplateNumberFormatFactory { @Override public TemplateNumberFormat get(final String params, final Locale locale, final Environment env) throws TemplateValueFormatException { TemplateFormatUtil.checkHasNoParameters(params); return new InterestNumberFormatFactory.InterestNumberFormat(locale); } private  InterestNumberFormatFactory(); @Override TemplateNumberFormat get(final String params, final Locale locale,
            final Environment env); static final InterestNumberFormatFactory INSTANCE; }
@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,10" + (char) 160 + "%"); }
@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%"); }
@Test void formattingEnglishZero() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> BigDecimal.ZERO; final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.00%"); }
@Test void formattingEnglishLongZero() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.000000000000000000"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.00%"); }
@Test void formattingEnglishRoundingUp() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00049"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.05%"); }
@Test void formattingEnglishRoundingEvenUp() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00055"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.06%"); }
@Test void formattingEnglishRoundingEvenDown() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00025"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.02%"); }
@Test void formattingEnglishRoundingDown() throws TemplateValueFormatException, TemplateModelException { final TemplateNumberFormat f = InterestNumberFormatFactory.INSTANCE.get("", Locale.ENGLISH, Environment.getCurrentEnvironment()); final TemplateNumberModel m = () -> new BigDecimal("0.00051"); final Object result = f.formatToPlainText(m); assertThat(result).isEqualTo("0.05%"); }
@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); }); }
@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 + "%"); }
@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,00" + (char) 160 + "%"); }