View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.tools.plugin.javadoc;
20  
21  import java.io.IOException;
22  import java.net.URI;
23  import java.util.stream.Stream;
24  
25  import org.apache.maven.tools.plugin.javadoc.FullyQualifiedJavadocReference.MemberType;
26  import org.junit.jupiter.params.ParameterizedTest;
27  import org.junit.jupiter.params.provider.Arguments;
28  import org.junit.jupiter.params.provider.MethodSource;
29  
30  class JavadocSiteIT {
31  
32      static Stream<Arguments> javadocBaseUrls() {
33          // only test LTS versions by default
34          return Stream.of(
35                  Arguments.of(URI.create("https://docs.oracle.com/en/java/javase/17/docs/api/")),
36                  Arguments.of(URI.create("https://docs.oracle.com/en/java/javase/11/docs/api/")),
37                  Arguments.of(URI.create("https://docs.oracle.com/javase/8/docs/api/")));
38      }
39  
40      @ParameterizedTest
41      @MethodSource("javadocBaseUrls")
42      void testConstructors(URI javadocBaseUrl) throws IOException {
43          JavadocSite site = new JavadocSite(javadocBaseUrl, null);
44          JavadocSiteTest.assertUrlValid(site.createLink(new FullyQualifiedJavadocReference(
45                  "java.lang", "String", "String(byte[],int)", MemberType.CONSTRUCTOR, true)));
46      }
47  
48      @ParameterizedTest
49      @MethodSource("javadocBaseUrls")
50      void testMethods(URI javadocBaseUrl) throws IOException {
51          JavadocSite site = new JavadocSite(javadocBaseUrl, null);
52          JavadocSiteTest.assertUrlValid(site.createLink(new FullyQualifiedJavadocReference(
53                  "java.lang", "String", "copyValueOf(char[],int,int)", MemberType.METHOD, true)));
54      }
55  
56      @ParameterizedTest
57      @MethodSource("javadocBaseUrls")
58      void testFields(URI javadocBaseUrl) throws IOException {
59          JavadocSite site = new JavadocSite(javadocBaseUrl, null);
60          JavadocSiteTest.assertUrlValid(site.createLink(new FullyQualifiedJavadocReference(
61                  "java.lang", "String", "CASE_INSENSITIVE_ORDER", MemberType.FIELD, true)));
62      }
63  
64      @ParameterizedTest
65      @MethodSource("javadocBaseUrls")
66      void testNestedClass(URI javadocBaseUrl) throws IOException {
67          JavadocSite site = new JavadocSite(javadocBaseUrl, null);
68          JavadocSiteTest.assertUrlValid(
69                  site.createLink(new FullyQualifiedJavadocReference("java.util", "Map.Entry", true)));
70      }
71  }