HELP! JUnit can't handle Chinese string on IBM JDK

It's a strange case.

env:
IDEA: 6.0.5 with encoding=system default
JDK: IBM JDK 1.4.2
JUnit

question:
class myTest extends TestCase {
public void test1() {
System.out.print("?? is a beatiful country."); //here simply output a chinese string
}
public void test2() {
FileWriter file = new FileWriter("c:/test.txt");
file.write("??");
file.flush();
file.close();
}
}

However, in Junit console, test1 print out some malformed string such as:
???? is a beatiful country.
But, test2 create a file, in which include the correct encodinged string.

Go on to test. If I create a java class like that:
class Main {
static public void main(String[] args) {
System.out.print("??");
}
}
The same IBM JDK, then this time the console give the corrent string.

So, please give me some suggestion or the reason may exists.
Thanks all.

3 comments

Please make sure (in the Run configuration|Junit|VM parameters) that you
have passed correct encoding in the -Dfile.encoding= command line parameter.


--
regards,
--
Alexey Kudravtsev
Software Developer
JetBrains, Inc, http://www.jetbrains.com
"Develop with pleasure!"

"tttk" <no_reply@jetbrains.com> wrote in message
news:30846587.1179924238164.JavaMail.itn@is.intellij.net...

It's a strange case.

>

env:
IDEA: 6.0.5 with encoding=system default
JDK: IBM JDK 1.4.2
JUnit

>

question:
class myTest extends TestCase {
public void test1() {
System.out.print("?? is a beatiful country."); //here simply output a
chinese string
}
public void test2() {
FileWriter file = new FileWriter("c:/test.txt");
file.write("??");
file.flush();
file.close();
}
}

>

However, in Junit console, test1 print out some malformed string such as:
???? is a beatiful country.
But, test2 create a file, in which include the correct encodinged string.

>

Go on to test. If I create a java class like that:
class Main {
static public void main(String[] args) {
System.out.print("??");
}
}
The same IBM JDK, then this time the console give the corrent string.

>

So, please give me some suggestion or the reason may exists.
Thanks all.



0

Thanks anymore.

I checked the VM setting in the Run configuration|Junit|VM parameters, there is nothing set there.
Then I checked the output in JUnit's Run console, the command line gives like that:
"D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\bin\java" -Didea.launcher.port=7533 "-Didea.launcher.bin.path=D:\Program Files\JetBrains\IntelliJ IDEA 6.0\bin" -Dfile.encoding=GB18030 -classpath "D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\charsets.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\core.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\graphics.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmcertpathprovider.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjaasactivelm.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjaaslm.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjcefw.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjgssprovider.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjssefips.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmjsseprovider.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmorb.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmorbapi.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ibmpkcs.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\plugin.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\security.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\server.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\xml.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\dumpfmt.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\gskikm.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmjcefips.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmjceprovider.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmjsseprovider2.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmpkcs11.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmpkcs11impl.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ibmspnego.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\indicim.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\iwsorbutil.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\jaccess.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\JawBridge.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\jdmpview.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\ldapsec.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\oldcertpath.jar;D:\Program Files\IBM\Rational\SDP\6.0\runtimes\base_v6\java\jre\lib\ext\PD.jar;D:\My Projects\Java\test\classes\production\test;D:\My Projects\Java\lib\junit\junit.jar;D:\My Projects\Java\lib\spring\dist\spring-mock.jar;D:\Program Files\JetBrains\IntelliJ IDEA 6.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 MyTest,testEncoding

In fact, GB18030 is my system's default encoding. However, if I use Sun JDK, everything is OK.
What's wrong with me?

0

Please sign in to leave a comment.