View Javadoc
1   /*
2    * Copyright (C) 2013 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.groovyworkarounds;
18  
19  import org.junit.Test;
20  
21  import java.io.File;
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  import static java.util.Collections.singletonList;
26  import static org.junit.Assert.*;
27  
28  
29  /**
30   * Unit tests for the DotGroovyFile class.
31   *
32   * @author Keegan Witt
33   */
34  public class DotGroovyFileTest {
35  
36      @Test
37      public void testGroovyWithCustomExtension() {
38          DotGroovyFile[] dotGroovyFiles = new DotGroovyFile[]{
39                  new DotGroovyFile("pathname.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
40                  new DotGroovyFile("parent", "child.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
41                  new DotGroovyFile(new File("parent"), "child.ext").setScriptExtensions(new HashSet<>(singletonList("ext"))),
42                  new DotGroovyFile(new File("filename.ext")).setScriptExtensions(new HashSet<>(singletonList("ext"))),
43                  new DotGroovyFile(new File("filename.ext").toURI()).setScriptExtensions(new HashSet<>(singletonList("ext")))
44          };
45          for (DotGroovyFile dotGroovyFile : dotGroovyFiles) {
46              assertTrue(dotGroovyFile.getName() + " doesn't end with .groovy", dotGroovyFile.getName().endsWith(".groovy"));
47          }
48      }
49  
50      @Test
51      public void testNonGroovyFile() {
52          DotGroovyFile[] dotGroovyFiles = new DotGroovyFile[]{
53                  new DotGroovyFile("pathname.ext"),
54                  new DotGroovyFile("parent", "child.ext"),
55                  new DotGroovyFile(new File("parent"), "child.ext"),
56                  new DotGroovyFile(new File("filename.ext")),
57                  new DotGroovyFile(new File("filename.ext").toURI())
58          };
59          for (DotGroovyFile dotGroovyFile : dotGroovyFiles) {
60              assertFalse(dotGroovyFile.getName() + " ends with .groovy", dotGroovyFile.getName().endsWith(".groovy"));
61          }
62      }
63  
64      @Test
65      public void testGettersAndSetters() {
66          Set<String> extensions = new HashSet<>();
67          extensions.add("ext");
68          DotGroovyFile dotGroovyFile = new DotGroovyFile("")
69                  .setScriptExtensions(extensions);
70          assertEquals(extensions, dotGroovyFile.getScriptExtensions());
71      }
72  
73  }