View Javadoc
1   /*
2    * Copyright 2014 the original author or authors.
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.codehaus.gmavenplus.mojo;
18  
19  import org.apache.maven.project.MavenProject;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.mockito.Mock;
23  import org.mockito.MockitoAnnotations;
24  
25  import java.io.File;
26  
27  import static org.mockito.Mockito.never;
28  import static org.mockito.Mockito.verify;
29  
30  
31  /**
32   * Unit tests for the AddTestStubSourcesMojo class.
33   *
34   * @author Keegan Witt
35   */
36  public class AddTestStubSourcesMojoTest {
37      private AddTestStubSourcesMojo addTestStubSourcesMojo;
38      @Mock
39      private MavenProject project;
40      @Mock
41      private File outputDirectory;
42  
43      @Before
44      public void setup() {
45          MockitoAnnotations.openMocks(this);
46          addTestStubSourcesMojo = new AddTestStubSourcesMojo();
47          addTestStubSourcesMojo.project = project;
48          addTestStubSourcesMojo.testStubsOutputDirectory = outputDirectory;
49      }
50  
51      @Test
52      public void testAddsTestStubsToSources() {
53          addTestStubSourcesMojo.execute();
54          verify(project).addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
55      }
56  
57      @Test
58      public void testDoesNothingWhenSkipFlagIsSet() {
59          addTestStubSourcesMojo.skipTests = true;
60          addTestStubSourcesMojo.execute();
61          verify(project, never()).addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
62      }
63  }