Path: blob/master/test/langtools/jdk/javadoc/doclet/testConditionalPages/TestConditionalPages.java
40971 views
/*1* Copyright (c) 2020, 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 825472126* @summary Improve support for conditionally generated files27* @library /tools/lib ../../lib28* @modules jdk.javadoc/jdk.javadoc.internal.tool29* @build toolbox.ToolBox javadoc.tester.* TestConditionalPages30* @run main TestConditionalPages31*/323334import java.io.IOException;35import java.nio.file.Files;36import java.nio.file.Path;37import java.util.function.Consumer;3839import javadoc.tester.JavadocTester;40import toolbox.Task;41import toolbox.ToolBox;4243public class TestConditionalPages extends JavadocTester {4445public static void main(String... args) throws Exception {46TestConditionalPages tester = new TestConditionalPages();47tester.runTests(m -> new Object[] { Path.of(m.getName()) });48}4950ToolBox tb = new ToolBox();5152@Test53public void testConstantValues(Path base) throws IOException {54test(base, """55package p;56public class C {57public static final int ZERO = 0;58}59""",60"constant-values.html",61b -> checkOutput("index-all.html", b, "Constant Field Values"));62}6364@Test65public void testDeprecated(Path base) throws IOException {66test(base, """67package p;68@Deprecated69public class C { }70""",71"deprecated-list.html",72b -> checkOutput("index-all.html", b, "Deprecated"));73}7475@Test76public void testSerializedForm(Path base) throws IOException {77test(base, """78package p;79import java.io.Serializable;80public class C implements Serializable { }81""",82"serialized-form.html",83b -> checkOutput("index-all.html", b, "Serialized Form"));84}8586@Test87public void testSystemProperties(Path base) throws IOException {88test(base, """89package p;90/** This class uses {@systemProperty line.separator}. */91public class C { }92""",93"system-properties.html",94b -> checkOutput("index-all.html", b, "System Properties"));95}9697void test(Path base, String code, String file, Consumer<Boolean> extraChecks) throws IOException {98test(base.resolve("a"), code, file, extraChecks, true);99test(base.resolve("b"), "package p; public class C { }", file, extraChecks, false);100}101102void test(Path base, String code, String file, Consumer<Boolean> extraChecks, boolean expect) throws IOException {103Path src = Files.createDirectories(base.resolve("src"));104tb.writeJavaFiles(src, code);105106javadoc("-d", base.resolve("out").toString(),107"-sourcepath", src.toString(),108"p");109checkExit(Exit.OK);110111checkFiles(expect, file);112checkOutput(Output.OUT, expect, "Generating " + base.resolve("out").resolve(file));113extraChecks.accept(expect);114}115}116117118