1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.gmavenplus.util;
18
19 import org.apache.maven.plugin.logging.Log;
20 import org.junit.Test;
21 import org.mockito.ArgumentCaptor;
22
23 import static java.util.Collections.emptyList;
24 import static org.junit.Assert.*;
25 import static org.mockito.Mockito.*;
26
27
28
29
30
31
32
33 public class ClassWranglerTest {
34
35 @Test
36 public void testGetGroovyJar() throws Exception {
37 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
38 doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
39 doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
40 assertEquals("groovy-all-1.5.0.jar", classWrangler.getGroovyJar());
41 }
42
43 @Test
44 public void testGetGroovyVersionStringFromGroovySystemThenFromInvokerHelper() throws Exception {
45 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
46 doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to try other methods."))
47 .when(classWrangler).getClass(anyString());
48 doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
49 ArgumentCaptor<String> classArg = ArgumentCaptor.forClass(String.class);
50 classWrangler.getGroovyVersionString();
51 verify(classWrangler, times(2)).getClass(classArg.capture());
52 assertEquals("groovy.lang.GroovySystem", classArg.getAllValues().get(0));
53 assertEquals("org.codehaus.groovy.runtime.InvokerHelper", classArg.getAllValues().get(1));
54 }
55
56 @Test
57 public void testGetGroovyVersionStringFromJar() throws Exception {
58 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
59 doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
60 doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath();
61 assertEquals("1.5.0", classWrangler.getGroovyVersionString());
62 }
63
64 @Test
65 public void testGetGroovyVersionWithIndyFromJar() throws Exception {
66 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
67 doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
68 doReturn("some/path/groovy-all-2.4.0-indy.jar").when(classWrangler).getJarPath();
69 assertEquals("2.4.0", classWrangler.getGroovyVersion().toString());
70 }
71
72 @Test
73 public void testGetGroovyVersionWithGrooidFromJar() throws Exception {
74 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
75 doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString());
76 doReturn("some/path/groovy-all-2.4.0-grooid.jar").when(classWrangler).getJarPath();
77 assertEquals("2.4.0", classWrangler.getGroovyVersion().toString());
78 }
79
80 @Test
81 public void testIsGroovyIndyTrue() throws Exception {
82 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
83 doReturn(null).when(classWrangler).getClass(anyString());
84 assertTrue(classWrangler.isGroovyIndy());
85 }
86
87 @Test
88 public void testIsGroovyIndyFalse() throws Exception {
89 ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class)));
90 doThrow(new ClassNotFoundException("Throwing exception to make it appear Groovy is not indy.")).when(classWrangler).getClass(anyString());
91 assertFalse(classWrangler.isGroovyIndy());
92 }
93
94 }