Skip to content

Commit

Permalink
Merge pull request #129 from groovy/java-upgrade
Browse files Browse the repository at this point in the history
upgrade to Java 11
  • Loading branch information
keeganwitt authored Apr 30, 2019
2 parents b0590d6 + 25a066e commit a116ef7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: java
jdk: oraclejdk8
#jdk: openjdk12
jdk: oraclejdk11
sudo: false

# unit test
Expand Down
23 changes: 12 additions & 11 deletions src/test/java/org/codehaus/gmavenplus/util/ClassWranglerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package org.codehaus.gmavenplus.util;

import groovy.lang.GroovySystem;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

Expand All @@ -36,56 +34,59 @@ public class ClassWranglerTest {

@Test
public void testGetGroovyJar() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
assertEquals("groovy-all-1.5.0.jar", classWrangler.getGroovyJar());
}

@Test
public void testGetGroovyVersionStringFromGroovySystemThenFromInvokerHelper() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to try other methods."))
.when(classWrangler).getClass(anyString());
doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
ArgumentCaptor<String> classArg = ArgumentCaptor.forClass(String.class);
classWrangler.getGroovyVersionString();
verify(classWrangler, times(2)).getClass(classArg.capture());
assertEquals(GroovySystem.class.getCanonicalName(), classArg.getAllValues().get(0));
assertEquals(InvokerHelper.class.getCanonicalName(), classArg.getAllValues().get(1));
assertEquals("groovy.lang.GroovySystem", classArg.getAllValues().get(0));
assertEquals("org.codehaus.groovy.runtime.InvokerHelper", classArg.getAllValues().get(1));
}

@Test
public void testGetGroovyVersionStringFromJar() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
assertEquals("1.5.0", classWrangler.getGroovyVersionString());
}

@Test
public void testGetGroovyVersionWithIndyFromJar() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
doReturn("some/path/groovy-all-2.4.0-indy.jar").when(classWrangler).getJarPath();
assertEquals("2.4.0", classWrangler.getGroovyVersion().toString());
}

@Test
public void testGetGroovyVersionWithGrooidFromJar() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
doReturn("some/path/groovy-all-2.4.0-grooid.jar").when(classWrangler).getJarPath();
assertEquals("2.4.0", classWrangler.getGroovyVersion().toString());
}

@Test
public void testIsGroovyIndyTrue() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doReturn(null).when(classWrangler).getClass(anyString()); // make it appear Groovy is indy
assertTrue(classWrangler.isGroovyIndy());
}

@Test
public void testIsGroovyIndyFalse() throws Exception {
ClassWrangler classWrangler = spy(new ClassWrangler(mock(ClassLoader.class), mock(Log.class)));
ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class)));
doThrow(new ClassNotFoundException("Throwing exception to make it appear Groovy is not indy.")).when(classWrangler).getClass(anyString());
assertFalse(classWrangler.isGroovyIndy());
}
Expand Down

0 comments on commit a116ef7

Please sign in to comment.