View Javadoc
1   /*
2    * Copyright (C) 2011 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.codehaus.gmavenplus.model.internal.Version;
20  import org.junit.Before;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.*;
24  import static org.mockito.Mockito.doReturn;
25  import static org.mockito.Mockito.spy;
26  
27  
28  /**
29   * Unit tests for the AbstractGroovyMojo class.
30   *
31   * @author Keegan Witt
32   */
33  public class AbstractGroovyMojoTest {
34      private AbstractGroovyMojo testMojo;
35  
36      @Before
37      public void setup() {
38          testMojo = spy(new TestGroovyMojo());
39      }
40  
41      @Test
42      public void testGetJavaVersion() {
43          assertTrue(testMojo.getJavaVersionString() != null && !testMojo.getJavaVersionString().isEmpty());
44          assertNotNull(testMojo.getJavaVersion());
45      }
46  
47      @Test
48      public void testIsJavaSupportIndy() {
49          doReturn(Version.parseFromString("1.7.0_45")).when(testMojo).getJavaVersion();
50          assertTrue(testMojo.isJavaSupportIndy());
51      }
52  
53      @Test
54      public void testIsJavaSupportIndyNo() {
55          doReturn(Version.parseFromString("1.6.0_45")).when(testMojo).getJavaVersion();
56          assertFalse(testMojo.isJavaSupportIndy());
57      }
58  
59      @Test
60      public void testIsJavaSupportPreviewFeatures() {
61          doReturn(Version.parseFromString("12.0.1")).when(testMojo).getJavaVersion();
62          assertTrue(testMojo.isJavaSupportPreviewFeatures());
63      }
64  
65      @Test
66      public void testIsJavaSupportPreviewFeaturesNo() {
67          doReturn(Version.parseFromString("11.0.3")).when(testMojo).getJavaVersion();
68          assertFalse(testMojo.isJavaSupportPreviewFeatures());
69      }
70  
71      public static class TestGroovyMojo extends AbstractGroovyMojo {
72          @Override
73          public void execute() {
74          }
75      }
76  
77  }