8062348: langtools tests should close file manager (group 1)

Reviewed-by: darcy
This commit is contained in:
Jonathan Gibbons 2014-10-29 17:25:23 -07:00
parent b587478f7c
commit 8bd23f1681
145 changed files with 2701 additions and 2452 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -54,16 +54,17 @@ public class GetTask_FileObjectsTest extends APITest {
File testSrc = new File(System.getProperty("test.src"));
File srcFile = new File(testSrc, "pkg/C.java");
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
if (t.call()) {
System.err.println("task succeeded");
checkFiles(outDir, standardExpectFiles);
} else {
throw new Exception("task failed");
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
if (t.call()) {
System.err.println("task succeeded");
checkFiles(outDir, standardExpectFiles);
} else {
throw new Exception("task failed");
}
}
}
@ -75,16 +76,17 @@ public class GetTask_FileObjectsTest extends APITest {
public void testMemoryFileObject() throws Exception {
JavaFileObject srcFile = createSimpleJavaFileObject();
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
if (t.call()) {
System.err.println("task succeeded");
checkFiles(outDir, standardExpectFiles);
} else {
throw new Exception("task failed");
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
if (t.call()) {
System.err.println("task succeeded");
checkFiles(outDir, standardExpectFiles);
} else {
throw new Exception("task failed");
}
}
}
@ -96,15 +98,16 @@ public class GetTask_FileObjectsTest extends APITest {
File testSrc = new File(System.getProperty("test.src"));
File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
try {
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
error("getTask succeeded, no exception thrown");
} catch (IllegalArgumentException e) {
System.err.println("exception caught as expected: " + e);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);
try {
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
error("getTask succeeded, no exception thrown");
} catch (IllegalArgumentException e) {
System.err.println("exception caught as expected: " + e);
}
}
}
@ -114,15 +117,16 @@ public class GetTask_FileObjectsTest extends APITest {
@Test
public void testNull() throws Exception {
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
try {
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
error("getTask succeeded, no exception thrown");
} catch (NullPointerException e) {
System.err.println("exception caught as expected: " + e);
try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
File outDir = getOutDir();
fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));
Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);
try {
DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
error("getTask succeeded, no exception thrown");
} catch (NullPointerException e) {
System.err.println("exception caught as expected: " + e);
}
}
}