Special characters in Java string literals aren't interpreted correctly


(nerminme1) #1

Hello

I have a problem with gradle builds espacially tests

When executing tests from gradle some special characters won’t be overtaken right.

To explain the situation here is the UnitTest:

@Test
  public void testGetAsString() {
    when(this.value.doubleValue()).thenReturn(new Double(2222.22));
    assertEquals("2.222,22 €", this.moneyConverter.getAsString(null, mockComponent, value));
  }

and here the ouput of the gradle test:

org.junit.ComparisonFailure: expected:<2.222,22 [€]> but was:<2.222,22 [€]>
   at org.junit.Assert.assertEquals(Assert.java:125)
   at org.junit.Assert.assertEquals(Assert.java:147)
   at com.ergo.eip.portlet.common.converter.MoneyConverterTest.testGetAsString(MoneyConverterTest.java:51)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)

That must be a gradle thing, because on maven I can execute the test without an error. Can anyone help me?

Lg

PS: I use Eclipse Kepler and

------------------------------------------------------------ Gradle 1.4 ------------------------------------------------------------

Gradle build time: Montag, 28. Jõnner 2013 03:42 Uhr UTC Groovy: 1.8.6 Ant: Apache Ant™ version 1.8.4 compiled on May 22 2012 Ivy: 2.2.0 JVM: 1.6.0_31 (Sun Microsystems Inc. 20.6-b01) OS: Windows 7 6.1 amd64


(Peter Niederwieser) #2

You might have to set the correct encoding for your source files. (By default, the Java platform encoding will be used.) For example:

tasks.withType(JavaCompile) {
  options.encoding = "utf-8" // adapt as necessary
}

(nerminme1) #3

thank you very much :wink: