Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/api/basic/GetTask_FileObjectsTest.java
38828 views
/*1* Copyright (c) 2012, 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* @build APITest28* @run main GetTask_FileObjectsTest29*/3031import java.io.File;32import java.util.Arrays;33import javax.tools.DocumentationTool;34import javax.tools.DocumentationTool.DocumentationTask;35import javax.tools.JavaFileObject;36import javax.tools.StandardJavaFileManager;37import javax.tools.ToolProvider;3839/**40* Tests for DocumentationTool.getTask fileObjects parameter.41*/42public class GetTask_FileObjectsTest extends APITest {43public static void main(String... args) throws Exception {44new GetTask_FileObjectsTest().run();45}4647/**48* Verify that expected output files are written via the file manager,49* for a source file read from the file system with StandardJavaFileManager.50*/51@Test52public void testStandardFileObject() throws Exception {53File testSrc = new File(System.getProperty("test.src"));54File srcFile = new File(testSrc, "pkg/C.java");55DocumentationTool tool = ToolProvider.getSystemDocumentationTool();56StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);57File outDir = getOutDir();58fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));59Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);60DocumentationTask t = tool.getTask(null, fm, null, null, null, files);61if (t.call()) {62System.err.println("task succeeded");63checkFiles(outDir, standardExpectFiles);64} else {65throw new Exception("task failed");66}67}6869/**70* Verify that expected output files are written via the file manager,71* for an in-memory file object.72*/73@Test74public void testMemoryFileObject() throws Exception {75JavaFileObject srcFile = createSimpleJavaFileObject();76DocumentationTool tool = ToolProvider.getSystemDocumentationTool();77StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);78File outDir = getOutDir();79fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));80Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);81DocumentationTask t = tool.getTask(null, fm, null, null, null, files);82if (t.call()) {83System.err.println("task succeeded");84checkFiles(outDir, standardExpectFiles);85} else {86throw new Exception("task failed");87}88}8990/**91* Verify bad file object is handled correctly.92*/93@Test94public void testBadFileObject() throws Exception {95File testSrc = new File(System.getProperty("test.src"));96File srcFile = new File(testSrc, "pkg/C.class"); // unacceptable file kind97DocumentationTool tool = ToolProvider.getSystemDocumentationTool();98StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);99File outDir = getOutDir();100fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));101Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(srcFile);102try {103DocumentationTask t = tool.getTask(null, fm, null, null, null, files);104error("getTask succeeded, no exception thrown");105} catch (IllegalArgumentException e) {106System.err.println("exception caught as expected: " + e);107}108}109110/**111* Verify null is handled correctly.112*/113@Test114public void testNull() throws Exception {115DocumentationTool tool = ToolProvider.getSystemDocumentationTool();116StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);117File outDir = getOutDir();118fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(outDir));119Iterable<? extends JavaFileObject> files = Arrays.asList((JavaFileObject) null);120try {121DocumentationTask t = tool.getTask(null, fm, null, null, null, files);122error("getTask succeeded, no exception thrown");123} catch (NullPointerException e) {124System.err.println("exception caught as expected: " + e);125}126}127128}129130131132