View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.krad.theme.util;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  
21  import java.io.File;
22  
23  /**
24   * Test cases for {@link ThemeBuilderUtils}
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class ThemeBuilderUtilsTest {
29  
30      /**
31       * Test the path between two files is correctly determined
32       */
33      @Test
34      public void testCalculatePathToFile() {
35          File fromFile = new File("/basedir/subDir1/foo.css");
36          File toFile = new File("/basedir/subDir2/foo.css");
37  
38          String path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile);
39  
40          Assert.assertEquals("Path incorrect for up one dir", "../subDir2/", path);
41  
42          fromFile = new File("/basedir/subDir1/foo.css");
43          toFile = new File("/basedir/subDir1/foo.css");
44  
45          path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile);
46  
47          Assert.assertEquals("Path incorrect for same dir", "", path);
48  
49          fromFile = new File("/basedir/dir1/subDir1/foo.css");
50          toFile = new File("/basedir/dir2/subDir2/foo.css");
51  
52          path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile);
53  
54          Assert.assertEquals("Path incorrect for up two dir", "../../dir2/subDir2/", path);
55  
56          fromFile = new File("/basedir/subDir1/foo.css");
57          toFile = new File("/basedir/subDir1/moreDir/foo.css");
58  
59          path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile);
60  
61          Assert.assertEquals("Path incorrect for sub dir", "moreDir/", path);
62      }
63  
64      /**
65       * Tests the addition of a string to a string array
66       */
67      @Test
68      public void testAddStringToArray() {
69          String[] array1 = new String[] {"a1", "a2"};
70          String stringToAdd = "b1";
71  
72          String[] combinedArray = ThemeBuilderUtils.addToArray(array1, stringToAdd);
73  
74          Assert.assertEquals("Combined array length is not correct", 3, combinedArray.length);
75  
76          Assert.assertEquals("a1", combinedArray[0]);
77          Assert.assertEquals("a2", combinedArray[1]);
78          Assert.assertEquals("b1", combinedArray[2]);
79      }
80  
81      /**
82       * Tests the addition of string arrays
83       */
84      @Test
85      public void testAddArrayToArray() {
86          String[] array1 = new String[] {"a1", "a2"};
87          String[] array2 = new String[] {"b1", "b2", "b3"};
88  
89          String[] combinedArray = ThemeBuilderUtils.addToArray(array1, array2);
90  
91          Assert.assertEquals("Combined array length is not correct", 5, combinedArray.length);
92  
93          Assert.assertEquals("a1", combinedArray[0]);
94          Assert.assertEquals("a2", combinedArray[1]);
95          Assert.assertEquals("b1", combinedArray[2]);
96          Assert.assertEquals("b2", combinedArray[3]);
97          Assert.assertEquals("b3", combinedArray[4]);
98  
99          array2 = null;
100 
101         combinedArray = ThemeBuilderUtils.addToArray(array1, array2);
102 
103         Assert.assertEquals("Combined array length is not correct", 2, combinedArray.length);
104 
105         Assert.assertEquals("a1", combinedArray[0]);
106         Assert.assertEquals("a2", combinedArray[1]);
107 
108         array1 = null;
109         array2 = new String[] {"b1", "b2", "b3"};
110 
111         combinedArray = ThemeBuilderUtils.addToArray(array1, array2);
112 
113         Assert.assertEquals("Combined array length is not correct", 3, combinedArray.length);
114 
115         Assert.assertEquals("b1", combinedArray[0]);
116         Assert.assertEquals("b2", combinedArray[1]);
117         Assert.assertEquals("b3", combinedArray[2]);
118     }
119 }