View Javadoc

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