From b3cfcb813bf6aeebae75307c7ea2ce22ffc43653 Mon Sep 17 00:00:00 2001 From: sdelamo Date: Fri, 30 Nov 2018 11:17:00 +0100 Subject: [PATCH] Fix formatCurrency behaviour for JDK 8 and 11 See: https://github.com/grails/grails-gsp/issues/36 --- .../grails/web/taglib/FormatTagLibSpec.groovy | 42 +++++++++++++++++++ .../web/taglib/FormatTagLibTests.groovy | 12 ------ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibSpec.groovy diff --git a/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibSpec.groovy b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibSpec.groovy new file mode 100644 index 0000000000..051cdd0a21 --- /dev/null +++ b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibSpec.groovy @@ -0,0 +1,42 @@ +package org.grails.web.taglib + +import grails.testing.web.taglib.TagLibUnitTest +import org.grails.plugins.web.taglib.FormatTagLib +import spock.lang.IgnoreIf +import spock.lang.Requires +import spock.lang.Specification + +class FormatTagLibSpec extends Specification implements TagLibUnitTest { + + @Requires({ jvm.isJava8() }) + void testFormatCurrencyForJava8() { + given: + BigDecimal number = "3.12325678" as BigDecimal + "3,12 €" == applyTemplate('', [number: number]) + } + + @IgnoreIf({ jvm.isJava8() }) + void testFormatCurrency() { + given: + BigDecimal number = "3.12325678" as BigDecimal + "3,12${new String([160] as char[])}€" == applyTemplate('', [number: number]) + } + + @Requires({ jvm.isJava8() }) + void testFormatCurrencyWithCodeAndLocaleForJava8() { + given: + BigDecimal number = "3.12325678" as BigDecimal + + expect: + "3,12 USD" == applyTemplate('', [number: number]) + } + + @IgnoreIf({ jvm.isJava8() }) + void testFormatCurrencyWithCodeAndLocale() { + given: + BigDecimal number = "3.12325678" as BigDecimal + + expect: + "3,12${new String([160] as char[])}\$" == applyTemplate('', [number: number]) + } +} diff --git a/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibTests.groovy b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibTests.groovy index bb77e887ea..d75efec125 100644 --- a/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibTests.groovy +++ b/grails-plugin-gsp/src/test/groovy/org/grails/web/taglib/FormatTagLibTests.groovy @@ -203,18 +203,6 @@ class FormatTagLibTests extends AbstractGrailsTagTests { assertOutputEquals("3.1233", template, [number: number]) } - void testFormatCurrency() { - def number = "3.12325678" as BigDecimal - def template = '' - assertOutputEquals("3,12 €", template, [number: number]) - } - - void testFormatCurrencyWithCodeAndLocale() { - def number = "3.12325678" as BigDecimal - def template = '' - assertOutputEquals("3,12 USD", template, [number: number]) - } - void testFormatCurrencyWithCode() { def number = "3.12325678" as BigDecimal def template = ''