1   package test.net.sourceforge.pmd.ast;
2   import static org.junit.Assert.assertEquals;
3   import net.sourceforge.pmd.PMD;
4   import net.sourceforge.pmd.TargetJDK1_4;
5   import net.sourceforge.pmd.ast.ASTCompilationUnit;
6   import net.sourceforge.pmd.ast.ASTMethodDeclarator;
7   
8   import org.junit.Ignore;
9   import org.junit.Test;
10  
11  import java.io.ByteArrayInputStream;
12  import java.io.InputStreamReader;
13  public class EncodingTest {
14  
15      @Ignore("FIXME")
16      @Test
17      public void testDecodingOfUTF8() throws Throwable {
18          //String platformEncoding = System.getProperty("file.encoding");
19          //String encoding = "ISO-8859-1";
20          String encoding = "UTF-8";
21  
22          String code = new String(TEST_UTF8.getBytes(), encoding);
23          InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(code.getBytes()));
24          ASTCompilationUnit acu = new TargetJDK1_4().createParser(isr).CompilationUnit();
25          String methodName = acu.findChildrenOfType(ASTMethodDeclarator.class).get(0).getImage();
26          assertEquals(new String("é".getBytes(), encoding), methodName);
27      }
28  
29      private static final String TEST_UTF8 =
30              "class Foo {" + PMD.EOL +
31              " void é() {}" + PMD.EOL +
32              " void fiddle() {}" + PMD.EOL +
33              "}";
34  
35      public static junit.framework.Test suite() {
36          return new junit.framework.JUnit4TestAdapter(EncodingTest.class);
37      }
38  }