1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.codehaus.gmavenplus.model.internal.Version;
22 import org.codehaus.gmavenplus.util.ClassWrangler;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27
28 import java.io.File;
29 import java.util.HashSet;
30 import java.util.Set;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35 import static org.mockito.Mockito.anyLong;
36 import static org.mockito.Mockito.atLeastOnce;
37 import static org.mockito.Mockito.doReturn;
38 import static org.mockito.Mockito.mock;
39 import static org.mockito.Mockito.verify;
40
41
42
43
44
45
46
47 public class AbstractGenerateStubsMojoTest {
48 private TestMojo testMojo;
49
50 @Mock
51 private MavenProject project;
52
53 @Mock
54 private FileSet fileSet;
55
56 @Mock
57 private File outputDirectory;
58
59 @Before
60 public void setup() {
61 MockitoAnnotations.openMocks(this);
62 doReturn("STUBBED_DIRECTORY").when(fileSet).getDirectory();
63 doReturn(new String[]{"STUBBED_INCLUDES"}).when(fileSet).getIncludesArray();
64 doReturn("STUBBED_STUBS_DIRECTORY").when(outputDirectory).getAbsolutePath();
65 File mockBaseDir = mock(File.class);
66 doReturn("STUBBED_BASEDIR").when(mockBaseDir).getAbsolutePath();
67 doReturn(mockBaseDir).when(project).getBasedir();
68 testMojo = new TestMojo();
69 testMojo.project = project;
70 }
71
72 @Test
73 public void testGetStubs() {
74 Set<File> stubs = testMojo.getStubs(outputDirectory);
75 assertEquals(0, stubs.size());
76 }
77
78 @Test
79 public void testGroovyVersionSupportsActionTrue() {
80 testMojo = new TestMojo("1.5.0");
81 assertTrue(testMojo.groovyVersionSupportsAction());
82 }
83
84 @Test
85 public void testGroovyVersionSupportsActionFalse() {
86 testMojo = new TestMojo("1.1-rc-3");
87 assertFalse(testMojo.groovyVersionSupportsAction());
88 }
89
90 @Test
91 public void testResetStubModifiedDates() {
92 File stub = mock(File.class);
93 Set<File> stubs = new HashSet<>();
94 stubs.add(stub);
95 testMojo.resetStubModifiedDates(stubs);
96 verify(stub, atLeastOnce()).setLastModified(anyLong());
97 }
98
99 @Test(expected = IllegalArgumentException.class)
100 public void testJava6WithUnsupportedGroovy() {
101 testMojo = new TestMojo("2.1.2");
102 testMojo.targetBytecode = "1.6";
103 testMojo.verifyGroovyVersionSupportsTargetBytecode();
104 }
105
106 @Test
107 public void testJava6WithSupportedGroovy() {
108 testMojo = new TestMojo("2.1.3");
109 testMojo.targetBytecode = "1.6";
110 testMojo.verifyGroovyVersionSupportsTargetBytecode();
111 }
112
113 @Test(expected = IllegalArgumentException.class)
114 public void testJava7WithUnsupportedGroovy() {
115 testMojo = new TestMojo("2.1.2");
116 testMojo.targetBytecode = "1.7";
117 testMojo.verifyGroovyVersionSupportsTargetBytecode();
118 }
119
120 @Test
121 public void testJava7WithSupportedGroovy() {
122 testMojo = new TestMojo("2.1.3");
123 testMojo.targetBytecode = "1.7";
124 testMojo.verifyGroovyVersionSupportsTargetBytecode();
125 }
126
127 @Test(expected = IllegalArgumentException.class)
128 public void testJava8WithUnsupportedGroovy() {
129 testMojo = new TestMojo("2.3.2");
130 testMojo.targetBytecode = "1.8";
131 testMojo.verifyGroovyVersionSupportsTargetBytecode();
132 }
133
134 @Test
135 public void testJava8WithSupportedGroovy() {
136 testMojo = new TestMojo("2.3.3");
137 testMojo.targetBytecode = "1.8";
138 testMojo.verifyGroovyVersionSupportsTargetBytecode();
139 }
140
141 @Test(expected = IllegalArgumentException.class)
142 public void testJava9WithUnsupportedGroovy2_5() {
143 testMojo = new TestMojo("2.5.2");
144 testMojo.targetBytecode = "9";
145 testMojo.verifyGroovyVersionSupportsTargetBytecode();
146 }
147
148 @Test
149 public void testJava9WithSupportedGroovy2_5() {
150 testMojo = new TestMojo("2.5.3");
151 testMojo.targetBytecode = "9";
152 testMojo.verifyGroovyVersionSupportsTargetBytecode();
153 }
154
155 @Test(expected = IllegalArgumentException.class)
156 public void testJava9WithUnsupportedGroovy2_6() {
157 testMojo = new TestMojo("2.6.0-alpha-3");
158 testMojo.targetBytecode = "9";
159 testMojo.verifyGroovyVersionSupportsTargetBytecode();
160 }
161
162 @Test
163 public void testJava9WithSupportedGroovy2_6() {
164 testMojo = new TestMojo("2.6.0-alpha-4");
165 testMojo.targetBytecode = "9";
166 testMojo.verifyGroovyVersionSupportsTargetBytecode();
167 }
168
169 @Test(expected = IllegalArgumentException.class)
170 public void testJava9WithUnsupportedGroovy3() {
171 testMojo = new TestMojo("3.0.0-alpha-1");
172 testMojo.targetBytecode = "9";
173 testMojo.verifyGroovyVersionSupportsTargetBytecode();
174 }
175
176 @Test
177 public void testJava9WithSupportedGroovy3() {
178 testMojo = new TestMojo("3.0.0-alpha-2");
179 testMojo.targetBytecode = "9";
180 testMojo.verifyGroovyVersionSupportsTargetBytecode();
181 }
182
183 @Test(expected = IllegalArgumentException.class)
184 public void testJava9WithUnsupportedGroovyIndy() {
185 testMojo = new TestMojo("2.5.2", true);
186 testMojo.targetBytecode = "9";
187 testMojo.verifyGroovyVersionSupportsTargetBytecode();
188 }
189
190 @Test
191 public void testJava9WithSupportedGroovyIndy() {
192 testMojo = new TestMojo("2.5.3", true);
193 testMojo.targetBytecode = "9";
194 testMojo.verifyGroovyVersionSupportsTargetBytecode();
195 }
196
197 @Test(expected = IllegalArgumentException.class)
198 public void testJava9WithUnsupportedGroovy3Indy() {
199 testMojo = new TestMojo("3.0.0-alpha-3", true);
200 testMojo.targetBytecode = "9";
201 testMojo.verifyGroovyVersionSupportsTargetBytecode();
202 }
203
204 @Test
205 public void testJava9WithSupportedGroovy3Indy() {
206 testMojo = new TestMojo("3.0.0-alpha-4", true);
207 testMojo.targetBytecode = "9";
208 testMojo.verifyGroovyVersionSupportsTargetBytecode();
209 }
210
211 @Test(expected = IllegalArgumentException.class)
212 public void testJava10WithUnsupportedGroovy() {
213 testMojo = new TestMojo("2.5.2");
214 testMojo.targetBytecode = "10";
215 testMojo.verifyGroovyVersionSupportsTargetBytecode();
216 }
217
218 @Test
219 public void testJava10WithSupportedGroovy() {
220 testMojo = new TestMojo("2.5.3");
221 testMojo.targetBytecode = "10";
222 testMojo.verifyGroovyVersionSupportsTargetBytecode();
223 }
224
225 @Test(expected = IllegalArgumentException.class)
226 public void testJava10WithUnsupportedGroovy3() {
227 testMojo = new TestMojo("3.0.0-alpha-3");
228 testMojo.targetBytecode = "10";
229 testMojo.verifyGroovyVersionSupportsTargetBytecode();
230 }
231
232 @Test
233 public void testJava10WithSupportedGroovy3() {
234 testMojo = new TestMojo("3.0.0-alpha-4");
235 testMojo.targetBytecode = "10";
236 testMojo.verifyGroovyVersionSupportsTargetBytecode();
237 }
238
239 @Test(expected = IllegalArgumentException.class)
240 public void testJava11WithUnsupportedGroovy() {
241 testMojo = new TestMojo("2.5.2");
242 testMojo.targetBytecode = "11";
243 testMojo.verifyGroovyVersionSupportsTargetBytecode();
244 }
245
246 @Test
247 public void testJava11WithSupportedGroovy() {
248 testMojo = new TestMojo("2.5.3");
249 testMojo.targetBytecode = "11";
250 testMojo.verifyGroovyVersionSupportsTargetBytecode();
251 }
252
253 @Test(expected = IllegalArgumentException.class)
254 public void testJava11WithUnsupportedGroovy3() {
255 testMojo = new TestMojo("3.0.0-alpha-3");
256 testMojo.targetBytecode = "11";
257 testMojo.verifyGroovyVersionSupportsTargetBytecode();
258 }
259
260 @Test
261 public void testJava11WithSupportedGroovy3() {
262 testMojo = new TestMojo("3.0.0-alpha-4");
263 testMojo.targetBytecode = "11";
264 testMojo.verifyGroovyVersionSupportsTargetBytecode();
265 }
266
267 @Test(expected = IllegalArgumentException.class)
268 public void testJava12WithUnsupportedGroovy() {
269 testMojo = new TestMojo("2.5.2");
270 testMojo.targetBytecode = "12";
271 testMojo.verifyGroovyVersionSupportsTargetBytecode();
272 }
273
274 @Test
275 public void testJava12WithSupportedGroovy() {
276 testMojo = new TestMojo("2.5.3");
277 testMojo.targetBytecode = "12";
278 testMojo.verifyGroovyVersionSupportsTargetBytecode();
279 }
280
281 @Test(expected = IllegalArgumentException.class)
282 public void testJava12WithUnsupportedGroovy3() {
283 testMojo = new TestMojo("3.0.0-alpha-3");
284 testMojo.targetBytecode = "12";
285 testMojo.verifyGroovyVersionSupportsTargetBytecode();
286 }
287
288 @Test
289 public void testJava12WithSupportedGroovy3() {
290 testMojo = new TestMojo("3.0.0-alpha-4");
291 testMojo.targetBytecode = "12";
292 testMojo.verifyGroovyVersionSupportsTargetBytecode();
293 }
294
295 @Test(expected = IllegalArgumentException.class)
296 public void testJava13WithUnsupportedGroovy() {
297 testMojo = new TestMojo("2.5.6");
298 testMojo.targetBytecode = "13";
299 testMojo.verifyGroovyVersionSupportsTargetBytecode();
300 }
301
302 @Test
303 public void testJava13WithSupportedGroovy() {
304 testMojo = new TestMojo("2.5.7");
305 testMojo.targetBytecode = "13";
306 testMojo.verifyGroovyVersionSupportsTargetBytecode();
307 }
308
309 @Test(expected = IllegalArgumentException.class)
310 public void testJava13WithUnsupportedGroovy3() {
311 testMojo = new TestMojo("3.0.0-alpha-4");
312 testMojo.targetBytecode = "13";
313 testMojo.verifyGroovyVersionSupportsTargetBytecode();
314 }
315
316 @Test
317 public void testJava13WithSupportedGroovy3() {
318 testMojo = new TestMojo("3.0.0-beta-1");
319 testMojo.targetBytecode = "13";
320 testMojo.verifyGroovyVersionSupportsTargetBytecode();
321 }
322
323 @Test(expected = IllegalArgumentException.class)
324 public void testJava14WithUnsupportedGroovy() {
325 testMojo = new TestMojo("3.0.0-beta-1");
326 testMojo.targetBytecode = "14";
327 testMojo.verifyGroovyVersionSupportsTargetBytecode();
328 }
329
330 @Test
331 public void testJava14WithSupportedGroovy() {
332 testMojo = new TestMojo("3.0.0-beta-2");
333 testMojo.targetBytecode = "14";
334 testMojo.verifyGroovyVersionSupportsTargetBytecode();
335 }
336
337 @Test(expected = IllegalArgumentException.class)
338 public void testJava15WithUnsupportedGroovy() {
339 testMojo = new TestMojo("3.0.2");
340 testMojo.targetBytecode = "15";
341 testMojo.verifyGroovyVersionSupportsTargetBytecode();
342 }
343
344 @Test
345 public void testJava15WithSupportedGroovy() {
346 testMojo = new TestMojo("3.0.3");
347 testMojo.targetBytecode = "15";
348 testMojo.verifyGroovyVersionSupportsTargetBytecode();
349 }
350
351 @Test(expected = IllegalArgumentException.class)
352 public void testJava16WithUnsupportedGroovy() {
353 testMojo = new TestMojo("3.0.5");
354 testMojo.targetBytecode = "16";
355 testMojo.verifyGroovyVersionSupportsTargetBytecode();
356 }
357
358 @Test
359 public void testJava16WithSupportedGroovy() {
360 testMojo = new TestMojo("3.0.6");
361 testMojo.targetBytecode = "16";
362 testMojo.verifyGroovyVersionSupportsTargetBytecode();
363 }
364
365 @Test(expected = IllegalArgumentException.class)
366 public void testJava17WithUnsupportedGroovy() {
367 testMojo = new TestMojo("3.0.7");
368 testMojo.targetBytecode = "17";
369 testMojo.verifyGroovyVersionSupportsTargetBytecode();
370 }
371
372 @Test
373 public void testJava17WithSupportedGroovy() {
374 testMojo = new TestMojo("3.0.8");
375 testMojo.targetBytecode = "17";
376 testMojo.verifyGroovyVersionSupportsTargetBytecode();
377 }
378
379 @Test(expected = IllegalArgumentException.class)
380 public void testJava17WithUnsupportedGroovy4() {
381 testMojo = new TestMojo("4.0.0-alpha-2");
382 testMojo.targetBytecode = "17";
383 testMojo.verifyGroovyVersionSupportsTargetBytecode();
384 }
385
386 @Test
387 public void testJava17WithSupportedGroovy4() {
388 testMojo = new TestMojo("4.0.0-alpha-3");
389 testMojo.targetBytecode = "17";
390 testMojo.verifyGroovyVersionSupportsTargetBytecode();
391 }
392
393 @Test(expected = IllegalArgumentException.class)
394 public void testJava18WithUnsupportedGroovy() {
395 testMojo = new TestMojo("4.0.0-alpha-3");
396 testMojo.targetBytecode = "18";
397 testMojo.verifyGroovyVersionSupportsTargetBytecode();
398 }
399
400 @Test
401 public void testJava18WithSupportedGroovy() {
402 testMojo = new TestMojo("4.0.0-beta-1");
403 testMojo.targetBytecode = "18";
404 testMojo.verifyGroovyVersionSupportsTargetBytecode();
405 }
406
407 @Test(expected = IllegalArgumentException.class)
408 public void testJava19WithUnsupportedGroovy() {
409 testMojo = new TestMojo("4.0.1");
410 testMojo.targetBytecode = "19";
411 testMojo.verifyGroovyVersionSupportsTargetBytecode();
412 }
413
414 @Test
415 public void testJava19WithSupportedGroovy() {
416 testMojo = new TestMojo("4.0.2");
417 testMojo.targetBytecode = "19";
418 testMojo.verifyGroovyVersionSupportsTargetBytecode();
419 }
420
421 @Test(expected = IllegalArgumentException.class)
422 public void testJava20WithUnsupportedGroovy() {
423 testMojo = new TestMojo("4.0.5");
424 testMojo.targetBytecode = "20";
425 testMojo.verifyGroovyVersionSupportsTargetBytecode();
426 }
427
428 @Test
429 public void testJava20WithSupportedGroovy() {
430 testMojo = new TestMojo("4.0.6");
431 testMojo.targetBytecode = "20";
432 testMojo.verifyGroovyVersionSupportsTargetBytecode();
433 }
434
435 @Test(expected = IllegalArgumentException.class)
436 public void testJava21WithUnsupportedGroovy() {
437 testMojo = new TestMojo("4.0.10");
438 testMojo.targetBytecode = "21";
439 testMojo.verifyGroovyVersionSupportsTargetBytecode();
440 }
441
442 @Test
443 public void testJava21WithSupportedGroovy() {
444 testMojo = new TestMojo("4.0.11");
445 testMojo.targetBytecode = "21";
446 testMojo.verifyGroovyVersionSupportsTargetBytecode();
447 }
448
449 @Test(expected = IllegalArgumentException.class)
450 public void testJava22WithUnsupportedGroovy() {
451 testMojo = new TestMojo("4.0.15");
452 testMojo.targetBytecode = "22";
453 testMojo.verifyGroovyVersionSupportsTargetBytecode();
454 }
455
456 @Test
457 public void testJava22WithSupportedGroovy() {
458 testMojo = new TestMojo("4.0.16");
459 testMojo.targetBytecode = "22";
460 testMojo.verifyGroovyVersionSupportsTargetBytecode();
461 }
462
463 @Test(expected = IllegalArgumentException.class)
464 public void testJava22WithUnsupportedGroovy5() {
465 testMojo = new TestMojo("5.0.0-alpha-2");
466 testMojo.targetBytecode = "22";
467 testMojo.verifyGroovyVersionSupportsTargetBytecode();
468 }
469
470 @Test
471 public void testJava22WithSupportedGroovy5() {
472 testMojo = new TestMojo("5.0.0-alpha-3");
473 testMojo.targetBytecode = "22";
474 testMojo.verifyGroovyVersionSupportsTargetBytecode();
475 }
476
477 @Test(expected = IllegalArgumentException.class)
478 public void testJava23WithUnsupportedGroovy() {
479 testMojo = new TestMojo("4.0.20");
480 testMojo.targetBytecode = "23";
481 testMojo.verifyGroovyVersionSupportsTargetBytecode();
482 }
483
484 @Test
485 public void testJava23WithSupportedGroovy() {
486 testMojo = new TestMojo("4.0.21");
487 testMojo.targetBytecode = "23";
488 testMojo.verifyGroovyVersionSupportsTargetBytecode();
489 }
490
491 @Test(expected = IllegalArgumentException.class)
492 public void testJava23WithUnsupportedGroovy5() {
493 testMojo = new TestMojo("5.0.0-alpha-7");
494 testMojo.targetBytecode = "23";
495 testMojo.verifyGroovyVersionSupportsTargetBytecode();
496 }
497
498 @Test
499 public void testJava23WithSupportedGroovy5() {
500 testMojo = new TestMojo("5.0.0-alpha-8");
501 testMojo.targetBytecode = "23";
502 testMojo.verifyGroovyVersionSupportsTargetBytecode();
503 }
504
505 @Test(expected = IllegalArgumentException.class)
506 public void testJava24WithUnsupportedGroovy() {
507 testMojo = new TestMojo("4.0.23");
508 testMojo.targetBytecode = "24";
509 testMojo.verifyGroovyVersionSupportsTargetBytecode();
510 }
511
512 @Test
513 public void testJava24WithSupportedGroovy() {
514 testMojo = new TestMojo("4.0.24");
515 testMojo.targetBytecode = "24";
516 testMojo.verifyGroovyVersionSupportsTargetBytecode();
517 }
518
519 @Test(expected = IllegalArgumentException.class)
520 public void testJava24WithUnsupportedGroovy5() {
521 testMojo = new TestMojo("5.0.0-alpha-10");
522 testMojo.targetBytecode = "24";
523 testMojo.verifyGroovyVersionSupportsTargetBytecode();
524 }
525
526 @Test
527 public void testJava24WithSupportedGroovy5() {
528 testMojo = new TestMojo("5.0.0-alpha-11");
529 testMojo.targetBytecode = "24";
530 testMojo.verifyGroovyVersionSupportsTargetBytecode();
531 }
532
533 @Test(expected = IllegalArgumentException.class)
534 public void testJava25WithUnsupportedGroovy() {
535 testMojo = new TestMojo("4.0.26");
536 testMojo.targetBytecode = "25";
537 testMojo.verifyGroovyVersionSupportsTargetBytecode();
538 }
539
540 @Test
541 public void testJava25WithSupportedGroovy() {
542 testMojo = new TestMojo("4.0.27");
543 testMojo.targetBytecode = "25";
544 testMojo.verifyGroovyVersionSupportsTargetBytecode();
545 }
546
547 @Test(expected = IllegalArgumentException.class)
548 public void testJava25WithUnsupportedGroovy5() {
549 testMojo = new TestMojo("5.0.0-alpha-12");
550 testMojo.targetBytecode = "25";
551 testMojo.verifyGroovyVersionSupportsTargetBytecode();
552 }
553
554 @Test
555 public void testJava25WithSupportedGroovy5() {
556 testMojo = new TestMojo("5.0.0-alpha-13");
557 testMojo.targetBytecode = "25";
558 testMojo.verifyGroovyVersionSupportsTargetBytecode();
559 }
560
561 @Test(expected = IllegalArgumentException.class)
562 public void testUnrecognizedJava() {
563 testMojo = new TestMojo("2.1.2");
564 testMojo.targetBytecode = "unknown";
565 testMojo.verifyGroovyVersionSupportsTargetBytecode();
566 }
567
568 protected static class TestMojo extends AbstractGenerateStubsMojo {
569 protected TestMojo() {
570 this(GROOVY_1_8_2.toString(), false);
571 }
572
573 protected TestMojo(String groovyVersion) {
574 this(groovyVersion, false);
575 }
576
577 protected TestMojo(String groovyVersion, boolean indy) {
578 classWrangler = mock(ClassWrangler.class);
579 doReturn(Version.parseFromString(groovyVersion)).when(classWrangler).getGroovyVersion();
580 doReturn(indy).when(classWrangler).isGroovyIndy();
581 }
582
583 @Override
584 public void execute() {
585 }
586 }
587
588 }