View Javadoc
1   /*
2    * Copyright (C) 2013 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.apache.maven.shared.model.fileset.FileSet;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.mockito.Mock;
24  import org.mockito.MockitoAnnotations;
25  
26  import static java.util.Collections.singletonList;
27  import static org.mockito.Mockito.*;
28  
29  
30  /**
31   * Unit tests for the AddSourcesMojo class.
32   *
33   * @author Keegan Witt
34   */
35  public class AddSourcesMojoTest {
36      private AddSourcesMojo addSourcesMojo;
37  
38      private static final String PATH = "PATH";
39  
40      @Mock
41      private MavenProject project;
42  
43      @Before
44      public void setup() {
45          MockitoAnnotations.openMocks(this);
46          addSourcesMojo = new AddSourcesMojo();
47          addSourcesMojo.project = project;
48      }
49  
50      @Test
51      public void testAddSourcePathContainsPath() {
52          doReturn(singletonList(PATH)).when(project).getCompileSourceRoots();
53          FileSet fs = new FileSet();
54          fs.setDirectory(PATH);
55          addSourcesMojo.sources = new FileSet[]{fs};
56          addSourcesMojo.execute();
57          verify(project, never()).addCompileSourceRoot(anyString());
58      }
59  
60      @Test
61      public void testAddSourcePathNotContainsPath() {
62          doReturn(singletonList(PATH)).when(project).getCompileSourceRoots();
63          FileSet fs = new FileSet();
64          fs.setDirectory("OTHER PATH");
65          addSourcesMojo.sources = new FileSet[]{fs};
66          addSourcesMojo.execute();
67          verify(project, times(1)).addCompileSourceRoot(anyString());
68      }
69  
70  }