View Javadoc
1   package org.apache.maven.plugins.javadoc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.model.Plugin;
25  import org.apache.maven.plugin.MojoExecution;
26  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  import org.apache.maven.project.MavenProject;
29  import org.codehaus.plexus.util.FileUtils;
30  
31  import static org.assertj.core.api.Assertions.assertThat;
32  
33  /**
34   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
35   */
36  public class TestJavadocReportTest
37      extends AbstractMojoTestCase
38  {
39      /**
40       * Test the test-javadoc configuration for the plugin
41       *
42       * @throws Exception if any
43       */
44      public void testTestJavadoc()
45          throws Exception
46      {
47          File testPom =
48              new File( getBasedir(),
49                        "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml" );
50          TestJavadocReport mojo = (TestJavadocReport) lookupMojo( "test-javadoc", testPom );
51          
52          MojoExecution mojoExec = new MojoExecution( new Plugin(), "test-javadoc", null );
53  
54          setVariableValueToObject( mojo, "mojo", mojoExec );
55  
56          MavenProject currentProject = new MavenProjectStub();
57          currentProject.setGroupId( "GROUPID" );
58          currentProject.setArtifactId( "ARTIFACTID" );
59          
60          setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) );
61  
62          mojo.execute();
63  
64          File generatedFile =
65              new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/maven/AppTest.html" );
66          assertThat( generatedFile ).exists();
67          
68          File options = new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/options");
69          assertThat( FileUtils.fileRead( options ) ).contains( "junit-3.8.1.jar" );
70      }
71  }