Skip to content

Commit

Permalink
Fix formatCurrency behaviour for JDK 8 and 11
Browse files Browse the repository at this point in the history
See: #36
  • Loading branch information
sdelamo committed Nov 30, 2018
1 parent c9a2881 commit b3cfcb8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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<FormatTagLib> {

@Requires({ jvm.isJava8() })
void testFormatCurrencyForJava8() {
given:
BigDecimal number = "3.12325678" as BigDecimal
"3,12 €" == applyTemplate('<g:formatNumber type="currency" number="${number}" locale="fi_FI" />', [number: number])
}

@IgnoreIf({ jvm.isJava8() })
void testFormatCurrency() {
given:
BigDecimal number = "3.12325678" as BigDecimal
"3,12${new String([160] as char[])}" == applyTemplate('<g:formatNumber type="currency" number="${number}" locale="fi_FI" />', [number: number])
}

@Requires({ jvm.isJava8() })
void testFormatCurrencyWithCodeAndLocaleForJava8() {
given:
BigDecimal number = "3.12325678" as BigDecimal

expect:
"3,12 USD" == applyTemplate('<g:formatNumber type="currency" currencyCode="USD" number="${number}" locale="fi_FI" />', [number: number])
}

@IgnoreIf({ jvm.isJava8() })
void testFormatCurrencyWithCodeAndLocale() {
given:
BigDecimal number = "3.12325678" as BigDecimal

expect:
"3,12${new String([160] as char[])}\$" == applyTemplate('<g:formatNumber type="currency" currencyCode="USD" number="${number}" locale="fi_FI" />', [number: number])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,6 @@ class FormatTagLibTests extends AbstractGrailsTagTests {
assertOutputEquals("3.1233", template, [number: number])
}

void testFormatCurrency() {
def number = "3.12325678" as BigDecimal
def template = '<g:formatNumber type="currency" number="${number}" locale="fi_FI" />'
assertOutputEquals("3,12 €", template, [number: number])
}

void testFormatCurrencyWithCodeAndLocale() {
def number = "3.12325678" as BigDecimal
def template = '<g:formatNumber type="currency" currencyCode="USD" number="${number}" locale="fi_FI" />'
assertOutputEquals("3,12 USD", template, [number: number])
}

void testFormatCurrencyWithCode() {
def number = "3.12325678" as BigDecimal
def template = '<g:formatNumber type="currency" currencyCode="USD" number="${number}" locale="en_US" />'
Expand Down

0 comments on commit b3cfcb8

Please sign in to comment.