Search code examples
eclipseunicodejunitinfinitest

Eclipse: infinitest vs. JUnit: character encoding


I'm using infinitest in Eclipse and I have a strange phenomenon in connection with JUnit.

I have code that uses org.apache.http.HttpResponse.getEntity() and org.apache.http.entity.StringEntity. The JUnit test looks like this:

@Test
public void convertEncodedContentToString() throws UnsupportedEncodingException {
  HttpResponse httpResponseMock = Mockito.mock(HttpResponse.class);

  Mockito.when(httpResponseMock.getEntity()).thenReturn(new StringEntity("huiäöüß@€", HTTP.UTF_8));
  Assert.assertEquals("huiäöüß@€", parser.convertContentToString(httpResponseMock));
}

All source files are stored in UTF-8.

If I let JUnit execute this method, it works fine.

However, if infinitest runs this test it complains that the assertion fails.

ComparisonFailure (expected:<hui[äöüß@€]> but was:<hui[äöüß@€]>) in ResponseBodyParserFactoryTest.convertEncodedContentToString

Obviously there is a character encoding problem.

As infinitest has close to no options I have no idea how to help infinitest to run this test properly. Can anyone please help me out here?


Solution

  • You need to say to infinitest that it must use the UTF-8 charset to run the tests.

    Just add a file in your Eclipse project: "infinitest.args". In this file, add the following:

    -Dfile.encoding=UTF-8
    

    And so, inifinitest will use UTF-8

    User guide: http://infinitest.github.com/doc/user_guide.html specifically the 'Setting JVM Options' section