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.plugins.javadoc;
20  
21  import java.io.File;
22  
23  import org.apache.maven.model.Plugin;
24  import org.apache.maven.plugin.MojoExecution;
25  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
26  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.plexus.util.FileUtils;
29  
30  import static org.assertj.core.api.Assertions.assertThat;
31  
32  /**
33   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
34   */
35  public class TestJavadocReportTest extends AbstractMojoTestCase {
36      /**
37       * Test the test-javadoc configuration for the plugin
38       *
39       * @throws Exception if any
40       */
41      public void testTestJavadoc() throws Exception {
42          File testPom =
43                  new File(getBasedir(), "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml");
44          TestJavadocReport mojo = (TestJavadocReport) lookupMojo("test-javadoc", testPom);
45  
46          Plugin p = new Plugin();
47          p.setGroupId("org.apache.maven.plugins");
48          p.setArtifactId("maven-javadoc-plugin");
49          MojoExecution mojoExecution = new MojoExecution(p, "test-javadoc", null);
50  
51          setVariableValueToObject(mojo, "mojoExecution", mojoExecution);
52  
53          MavenProject currentProject = new MavenProjectStub();
54          currentProject.setGroupId("GROUPID");
55          currentProject.setArtifactId("ARTIFACTID");
56  
57          setVariableValueToObject(mojo, "session", newMavenSession(currentProject));
58  
59          mojo.execute();
60  
61          File generatedFile =
62                  new File(getBasedir(), "target/test/unit/test-javadoc-test/target/site/testapidocs/maven/AppTest.html");
63          assertThat(generatedFile).exists();
64  
65          File options = new File(getBasedir(), "target/test/unit/test-javadoc-test/target/site/testapidocs/options");
66          assertThat(FileUtils.fileRead(options)).contains("junit-3.8.1.jar");
67      }
68  }