Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have written a unit test, which controls if there are any encoding problems with german letters( ?,?,?,etc.)

@Test
public void testBodyWithDefaultCharset() throws UnsupportedEncodingException {
    when(backendDefinition.getProperty(BackendDetailsEnum.MAIL_CHARSET.getName())).thenReturn(null);
    Charset defaultCharset  = Charset.defaultCharset();
    when(packet.getPayload()).thenReturn(defaultCharset.encode("??ü??ü?").array());

    final String mailText = classUnderTest.prepareMailText(backendDefinition, packet);

    assertThat(mailText, is(equalTo("??ü??ü?")));
}

This test passes in windows pc but fails on jenkins, which is a linux environment. The error message is as follows;

Expected: is "??ü??ü?"
but: was "???????"

My question is, is it wrong to compare mailText with "??ü??ü?"? I thougt I don't need to state any encoding when I compare two strings.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
160 views
Welcome To Ask or Share your Answers For Others

1 Answer

Might be that your file encoding and stuff is defined differently on Windows then on Linux? It sounds like it is a difference in the file-encoding.

You may try to explicit set encoding in the .bashrc or by using the locale-program in Linux (example with UTF-8):

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

What is the output of:

locale?

Any different than the one expected?

Also do check which Charset the defaultCharset() is using. Try outputting the value on both Windows / Linux.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...