1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
25
26
27
28 public class ThemeBuilderUtilsTest {
29
30
31
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
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
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 }