test/tools/javac/api/6437999/T6437999.java

changeset 1855
c2d9303c3477
parent 1733
e39669aea0bd
child 2525
2eb010b6cb22
     1.1 --- a/test/tools/javac/api/6437999/T6437999.java	Tue Jun 25 20:08:52 2013 +0400
     1.2 +++ b/test/tools/javac/api/6437999/T6437999.java	Wed Jun 26 09:54:46 2013 -0700
     1.3 @@ -33,11 +33,28 @@
     1.4   */
     1.5  
     1.6  import java.io.File;
     1.7 +import java.io.IOException;
     1.8  import java.nio.charset.Charset;
     1.9 +import java.nio.file.Files;
    1.10 +import java.util.ArrayList;
    1.11  import java.util.Collections;
    1.12 +import java.util.List;
    1.13  import javax.tools.*;
    1.14 +import static java.nio.file.StandardOpenOption.*;
    1.15  
    1.16  public class T6437999 extends ToolTester {
    1.17 +    final File testFile = new File("Utf8.java");
    1.18 +    T6437999() throws IOException {
    1.19 +        createTestFile();
    1.20 +    }
    1.21 +    final void createTestFile() throws IOException {
    1.22 +        List<String> scratch = new ArrayList<>();
    1.23 +        scratch.add("// @author Peter von der Ah" + (char) 0xe9);
    1.24 +        scratch.add("class Utf8{}");
    1.25 +        Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"),
    1.26 +                CREATE, TRUNCATE_EXISTING);
    1.27 +    }
    1.28 +
    1.29      static class MyDiagnosticListener implements DiagnosticListener<JavaFileObject> {
    1.30          boolean error = false;
    1.31          public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    1.32 @@ -55,7 +72,7 @@
    1.33          dl.error = false;
    1.34          fm = getFileManager(tool, dl, Charset.forName("ASCII"));
    1.35          fm.handleOption("-source", sourceLevel.iterator());
    1.36 -        files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
    1.37 +        files = fm.getJavaFileObjects(testFile);
    1.38          tool.getTask(null, fm, null, null, null, files).call();
    1.39          if (!dl.error)
    1.40              throw new AssertionError("No error in ASCII mode");
    1.41 @@ -63,12 +80,12 @@
    1.42          dl.error = false;
    1.43          fm = getFileManager(tool, dl, Charset.forName("UTF-8"));
    1.44          fm.handleOption("-source", sourceLevel.iterator());
    1.45 -        files = fm.getJavaFileObjects(new File(test_src, "Utf8.java"));
    1.46 +        files = fm.getJavaFileObjects(testFile);
    1.47          task = tool.getTask(null, fm, null, null, null, files);
    1.48          if (dl.error)
    1.49              throw new AssertionError("Error in UTF-8 mode");
    1.50      }
    1.51 -    public static void main(String... args) {
    1.52 +    public static void main(String... args) throws IOException {
    1.53          new T6437999().test(args);
    1.54      }
    1.55  }

mercurial