2

I have a unit test that works well on most machine but one ubuntu box seems to not be able to compare special characters "?". The character itself should be â. On my machine the eclipse console displays it normally which encoding should we be playing with to ensure that this works.

The extracted text was wrong expected:<...tons. Il jette le bl[?me sur ....

but was:<...tons. Il jette le bl[?me sur .....

The test is ran within Eclipse Juno using Maven 2 using java 1.7

Does anyone have an idea...?

EDIT:

This behavior is only seen when running the unit test through Maven test and not when performing a run As Junit test... In the maven configuration we have the

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Which is set for both maven user settings and within the module's pom.xml file.

Stainedart
  • 1,929
  • 4
  • 32
  • 53

3 Answers3

3

Try to put UTF-8 encoding to maven-compiler-plugin inside <build> section in your pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.5.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • On unix machines it did on windows we also had to set the encoding from an OS level java variable which got is to work. – Stainedart Dec 04 '14 at 16:17
2

We manage to fix the issue with @Slawomir Jaranowski solution to THIS issue.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
  </configuration>
</plugin>
Marcio
  • 141
  • 1
  • 6
0

I recently had a problem with Unicode in JUnit. You can try using the escaped notation of the offending Unicode character in the JUnit test, or in the program itself.

In your case, try using /u0032 Instead of using â.

KJP
  • 519
  • 5
  • 10
  • The problem is that I do not want to re-write the text because it fails only on some specific machines. Our build environment is working fine. I was hoping to find a configuration change on the problematic machines to resolve the problem. – Stainedart Dec 17 '12 at 17:25
  • [This](http://stackoverflow.com/questions/4237581/comparing-unicode-characters-in-junit) question explains it pretty clearly, I think. My problem was that our build box got upgraded and the new glibc had problems, or something like that. Mapping it to escaped Unicode was deemed the easiest fix by my tech lead. Sorry I can't give you a more complete answer. – KJP Dec 17 '12 at 17:38