The following simple test is failing:
assertEquals(myStringComingFromTheDB, "£");
Giving:
Expected :£
Actual :£
I don't understand why this is happening, especially considering that is the encoding of the actual string (the one specified as second argument) to be wrong. The java file is saved as UTF8.
The following code:
System.out.println(bytesToHex(myStringComingFromTheDB.getBytes()));
System.out.println(bytesToHex("£".getBytes()));
Outputs:
C2A3
C382C2A3
Can anyone explain me why?
Thank you.
Update: I'm working under Windows 7.
Update 2: It's not related to JUnit, the following simple example:
byte[] bytes = "£".getBytes();
for(byte b : bytes)
{
System.out.println(Integer.toHexString(b));
}
Outputs:
ffffffc3
ffffff82
ffffffc2
ffffffa3
Update 3: I'm working in IntelliJ Idea, I already checked the options and the encoding is UTF8. Also, it's written in the bottom bar and when I select and right click the pound sign it says "Encoding (auto-detected): UTF-8".
Update 4: Opened the java file with a hex editor and the the pound sign is saved, correctly, as "C2A3".