Path: blob/master/test/langtools/jdk/javadoc/tool/api/basic/GetTask_FileObjectsTest.java
40983 views
/*1* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 649369026* @summary javadoc should have a javax.tools.Tool service provider27* @modules java.compiler28* jdk.compiler29* @build APITest30* @run main GetTask_FileObjectsTest31*/3233import java.io.File;34import java.util.Arrays;35import javax.tools.DocumentationTool;36import javax.tools.DocumentationTool.DocumentationTask;37import javax.tools.JavaFileObject;38import javax.tools.StandardJavaFileManager;39import javax.tools.ToolProvider;4041/**42* Tests for DocumentationTool.getTask fileObjects parameter.43*/44public class GetTask_FileObjectsTest extends APITest {45public static void main(String... args) throws Exception {46new GetTask_FileObjectsTest().run();47}4849/**50* Verify that expected output files are written via the file manager,51* for a source file read from the file system with StandardJavaFileManager.52*/53@Test54public void testStandardFileObject() throws Exception {55File testSrc = new File(System.getProperty("test.src"));56File srcFile = new File(testSrc, "pkg/C.java");57DocumentationTool tool = ToolProvider.getSystemDocumentationTool();58try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {59File outDir = getOutDir();60fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));61Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);62DocumentationTask t = tool.getTask(null, fm, null, null, null, files);63if (t.call()) {64System.err.println("task succeeded");65checkFiles(outDir, standardExpectFiles);66} else {67throw new Exception("task failed");68}69}70}7172/**73* Verify that expected output files are written via the file manager,74* for an in-memory file object.75*/76@Test77public void testMemoryFileObject() throws Exception {78JavaFileObject srcFile = createSimpleJavaFileObject();79DocumentationTool tool = ToolProvider.getSystemDocumentationTool();80try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {81File outDir = getOutDir();82fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));83Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);84DocumentationTask t = tool.getTask(null, fm, null, null, null, files);85if (t.call()) {86System.err.println("task succeeded");87checkFiles(outDir, standardExpectFiles);88} else {89throw new Exception("task failed");90}91}92}9394/**95* Verify bad file object is handled correctly.96*/97@Test98public void testBadFileObject() throws Exception {99File testSrc = new File(System.getProperty("test.src"));100File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind101DocumentationTool tool = ToolProvider.getSystemDocumentationTool();102try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {103File outDir = getOutDir();104fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));105Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);106try {107DocumentationTask t = tool.getTask(null, fm, null, null, null, files);108error("getTask succeeded, no exception thrown");109} catch (IllegalArgumentException e) {110System.err.println("exception caught as expected: " + e);111}112}113}114115/**116* Verify null is handled correctly.117*/118@Test119public void testNull() throws Exception {120DocumentationTool tool = ToolProvider.getSystemDocumentationTool();121try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {122File outDir = getOutDir();123fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));124Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);125try {126DocumentationTask t = tool.getTask(null, fm, null, null, null, files);127error("getTask succeeded, no exception thrown");128} catch (NullPointerException e) {129System.err.println("exception caught as expected: " + e);130}131}132}133134}135136137138