1   /*
2    * Copyright 2006 Eric Ballet Baz
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.maven.author.resolver;
18  
19  import java.io.File;
20  import java.net.URL;
21  
22  /**
23   * Unit test for the class JavadocAuthorResolver.
24   *
25   * @author Eric Ballet Baz
26   */
27  public class TestJavadocAuthorResolver extends AbstractTestAuthorResolver {
28  
29      /**
30       * @see org.apache.maven.author.resolver.AbstractTestAuthorResolver#getAuthorResolverClass()
31       */
32      protected final Class getAuthorResolverClass() {
33          return JavadocAuthorResolver.class;
34      }
35  
36      /**
37       * Test method resolveAuthors on a file without Javadoc author.
38       */
39      public final void testResolveAuthorWithoutJavadocAuthor() {
40          AuthorResolver resolver = instanciateAuthorResolver();
41  
42          URL url = getClass().getClassLoader().getResource("SampleFileWithoutJavadocAuthor.java");
43          assertNotNull(url);
44  
45          String[] authors = resolver.resolveAuthors(new File(url.getPath()));
46          assertNotNull(authors);
47          assertEquals(0, authors.length);
48      }
49  
50      /**
51       * Test method resolveAuthors on a file with one Javadoc author.
52       */
53      public final void testResolveAuthorWithOneJavadocAuthor() {
54          AuthorResolver resolver = instanciateAuthorResolver();
55  
56          URL url = getClass().getClassLoader().getResource("SampleFileWithOneJavadocAuthor.java");
57          assertNotNull(url);
58  
59          String[] authors = resolver.resolveAuthors(new File(url.getPath()));
60          assertNotNull(authors);
61          assertEquals(1, authors.length);
62          assertEquals("Sample Author 1", authors[0]);
63      }
64  
65      /**
66       * Test method resolveAuthors on a file with three Javadoc authors.
67       */
68      public final void testResolveAuthorWithThreeJavadocAuthors() {
69          AuthorResolver resolver = instanciateAuthorResolver();
70  
71          URL url = getClass().getClassLoader().getResource("SampleFileWithThreeJavadocAuthors.java");
72          assertNotNull(url);
73  
74          String[] authors = resolver.resolveAuthors(new File(url.getPath()));
75          assertNotNull(authors);
76          assertEquals(3, authors.length);
77  
78          assertEquals("Sample Author 1", authors[0]);
79          assertEquals("Sample Author 3", authors[1]);
80          assertEquals("Sample Author 2", authors[2]);
81      }
82  }