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 static org.mockito.Matchers.anyString;
23  import static org.mockito.Mockito.mock;
24  import static org.mockito.Mockito.never;
25  import static org.mockito.Mockito.times;
26  import static org.mockito.Mockito.verify;
27  import static org.mockito.Mockito.when;
28  
29  import java.io.File;
30  
31  import org.apache.maven.plugin.MojoExecutionException;
32  import org.apache.maven.plugin.MojoFailureException;
33  import org.apache.maven.plugin.logging.Log;
34  import org.apache.maven.plugins.javadoc.AbstractJavadocMojo;
35  
36  import junit.framework.TestCase;
37  
38  public class AbstractJavadocMojoTest
39      extends TestCase
40  {
41      AbstractJavadocMojo mojo;
42  
43      @Override
44      protected void setUp()
45          throws Exception
46      {
47          super.setUp();
48          mojo = new AbstractJavadocMojo()
49          {
50              @Override
51              public void doExecute()
52                  throws MojoExecutionException, MojoFailureException
53              {
54              }
55          };
56      }
57  
58      public void testMJAVADOC432_DetectLinksMessages()
59      {
60          Log log = mock( Log.class );
61          when( log.isErrorEnabled() ).thenReturn( true );
62          mojo.setLog( log );
63          mojo.outputDirectory = new File( "target/test-classes" );
64  
65          // first continues after warning, next exits with warning
66          assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), true ) );
67          assertFalse( mojo.isValidJavadocLink( "file://%%", true ) );
68          assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), true ) );
69          verify( log, times( 4 ) ).warn( anyString() );
70          verify( log, never() ).error( anyString() );
71  
72          // first continues after error, next exits with error
73          assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).getPath(), false ) );
74          assertFalse( mojo.isValidJavadocLink( "file://%%", false ) );
75          assertFalse( mojo.isValidJavadocLink( new File( "pom.xml" ).toURI().toString(), false ) );
76          verify( log, times( 4 ) ).error( anyString() );
77          verify( log, times( 4 ) ).warn( anyString() ); // no extra warnings
78      }
79  
80      public void testMJAVADOC527_DetectLinksRecursion()
81      {
82          Log log = mock( Log.class );
83          when( log.isErrorEnabled() ).thenReturn( true );
84          mojo.setLog( log );
85          mojo.outputDirectory = new File( "target/test-classes" );
86  
87          assertFalse( mojo.isValidJavadocLink( "http://javamail.java.net/mailapi/apidocs", false ) );
88          assertTrue( mojo.isValidJavadocLink( "http://commons.apache.org/proper/commons-lang/apidocs", false ) );
89      }
90  }