Skip to main content


Showing posts with the label Encoding

Junit - Test fails on French or German string assertion

In my previous post about building a regex to check a text without special characters but allow German and French. I met a problem that the unit test works fine on my machine using Eclipse, but it was fail when running on Jenkins' build job.

Here is my test:

@Test public void shouldAllowFrenchAndGermanCharacters(){ String source = "ÄäÖöÜüß áÁàÀâÂéÉèÈêÊîÎçÇ"; assertFalse(SpecialCharactersUtils.isExistSpecialCharater(source)); }
Production code:

public static boolean isExistNotAllowedCharacters(String source){ Pattern regex = Pattern.compile("^[a-zA-Z_0-9_ÄäÖöÜüß áÁàÀâÂéÉèÈêÊîÎçÇ]*$"); Matcher matcher = regex.matcher(source); return !matcher.matches(); }
The result likes the following:
Failed tests: SpecialCharactersUtilsTest.shouldAllowFrenchAndGermanCharacters:32 null
A guy from says:

"This is probably due to the default encoding used for your Java source files. The ö in the string literal in the JUnit source code …