View Javadoc
1   package org.codehaus.gmavenplus.mojo;
2   
3   import org.codehaus.gmavenplus.model.internal.Version;
4   import org.codehaus.gmavenplus.util.ClassWrangler;
5   import org.junit.Before;
6   import org.junit.Test;
7   import org.mockito.MockitoAnnotations;
8   
9   import static org.junit.Assert.assertFalse;
10  import static org.junit.Assert.assertTrue;
11  import static org.mockito.Mockito.doReturn;
12  import static org.mockito.Mockito.mock;
13  
14  /**
15   * Unit tests for the AbstractCompileMojo class.
16   *
17   * @author Keegan Witt
18   */
19  public class AbstractCompileMojoTest {
20      private TestMojo testMojo;
21  
22      @Before
23      public void setup() {
24          MockitoAnnotations.openMocks(this);
25          testMojo = new TestMojo();
26      }
27  
28      @Test
29      public void testGroovyVersionSupportsActionTrue() {
30          testMojo = new TestMojo("1.5.0");
31          assertTrue(testMojo.groovyVersionSupportsAction());
32      }
33  
34      @Test
35      public void testGroovyVersionSupportsActionFalse() {
36          testMojo = new TestMojo("1.1-rc-3");
37          assertFalse(testMojo.groovyVersionSupportsAction());
38      }
39  
40      protected static class TestMojo extends AbstractCompileMojo {
41          protected TestMojo() {
42              this(GROOVY_1_5_0.toString(), false);
43          }
44  
45          protected TestMojo(String groovyVersion) {
46              this(groovyVersion, false);
47          }
48  
49          protected TestMojo(String groovyVersion, boolean indy) {
50              classWrangler = mock(ClassWrangler.class);
51              doReturn(Version.parseFromString(groovyVersion)).when(classWrangler).getGroovyVersion();
52              doReturn(indy).when(classWrangler).isGroovyIndy();
53          }
54  
55          @Override
56          public void execute() {
57          }
58      }
59  
60  }