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  
21  import junit.framework.TestCase;
22  
23  /**
24   * @author Eric Ballet Baz
25   */
26  public abstract class AbstractTestAuthorResolver extends TestCase {
27  
28      protected abstract Class getAuthorResolverClass();
29  
30      public final void testDefautConstructor() {
31          AuthorResolver authorResolver = instanciateAuthorResolver();
32          assertNotNull(authorResolver);
33      }
34  
35      public final void testResolveAuthorsWithNullArgument() {
36          AuthorResolver authorResolver = instanciateAuthorResolver();
37  
38          try {
39              authorResolver.resolveAuthors(null);
40              fail("An IllegalArgumentException should have been thrown");
41  
42          } catch (IllegalArgumentException e) {
43              // Ok !
44              assertNotNull(e);
45          }
46      }
47  
48      public final void testResolveAuthorsWithDirectoryArgument() {
49          AuthorResolver authorResolver = instanciateAuthorResolver();
50          File rootDirectory = new File("/");
51  
52          try {
53              authorResolver.resolveAuthors(rootDirectory);
54              fail("An IllegalArgumentException should have been thrown");
55  
56          } catch (IllegalArgumentException e) {
57              // Ok !
58              assertNotNull(e);
59          }
60      }
61  
62      protected final AuthorResolver instanciateAuthorResolver() {
63          try {
64              return (AuthorResolver) getAuthorResolverClass().newInstance();
65          } catch (InstantiationException e) {
66              throw new RuntimeException(e);
67          } catch (IllegalAccessException e) {
68              throw new RuntimeException(e);
69          }
70      }
71  }