1 package org.codehaus.gmavenplus.groovyworkarounds;
2
3 import org.junit.Test;
4
5 import java.io.File;
6 import java.util.HashSet;
7 import java.util.Set;
8
9 import static java.util.Collections.singletonList;
10 import static org.junit.Assert.*;
11
12
13
14
15
16
17
18 public class DotGroovyFileTest {
19
20 @Test
21 public void testGroovyWithCustomExtension() {
22 DotGroovyFile[] dotGroovyFiles = new DotGroovyFile[]{
23 new DotGroovyFile("pathname.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
24 new DotGroovyFile("parent", "child.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
25 new DotGroovyFile(new File("parent"), "child.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
26 new DotGroovyFile(new File("filename.ext")).setScriptExtensions(new HashSet<>(singletonList("ext"))),
27 new DotGroovyFile(new File("filename.ext").toURI()).setScriptExtensions(new HashSet<>(singletonList("ext")))
28 };
29 for (DotGroovyFile dotGroovyFile : dotGroovyFiles) {
30 assertTrue(dotGroovyFile.getName() + " doesn't end with .groovy", dotGroovyFile.getName().endsWith(".groovy"));
31 }
32 }
33
34 @Test
35 public void testNonGroovyFile() {
36 DotGroovyFile[] dotGroovyFiles = new DotGroovyFile[]{
37 new DotGroovyFile("pathname.ext"),
38 new DotGroovyFile("parent", "child.ext"),
39 new DotGroovyFile(new File("parent"), "child.ext"),
40 new DotGroovyFile(new File("filename.ext")),
41 new DotGroovyFile(new File("filename.ext").toURI())
42 };
43 for (DotGroovyFile dotGroovyFile : dotGroovyFiles) {
44 assertFalse(dotGroovyFile.getName() + " ends with .groovy", dotGroovyFile.getName().endsWith(".groovy"));
45 }
46 }
47
48 @Test
49 public void testGettersAndSetters() {
50 Set<String> extensions = new HashSet<>();
51 extensions.add("ext");
52 DotGroovyFile dotGroovyFile = new DotGroovyFile("")
53 .setScriptExtensions(extensions);
54 assertEquals(extensions, dotGroovyFile.getScriptExtensions());
55 }
56
57 }