001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.theme.util; 017 018import org.junit.Assert; 019import org.junit.Test; 020 021import java.io.File; 022 023/** 024 * Test cases for {@link ThemeBuilderUtils} 025 * 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028public class ThemeBuilderUtilsTest { 029 030 /** 031 * Test the path between two files is correctly determined 032 */ 033 @Test 034 public void testCalculatePathToFile() { 035 File fromFile = new File("/basedir/subDir1/foo.css"); 036 File toFile = new File("/basedir/subDir2/foo.css"); 037 038 String path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); 039 040 Assert.assertEquals("Path incorrect for up one dir", "../subDir2/", path); 041 042 fromFile = new File("/basedir/subDir1/foo.css"); 043 toFile = new File("/basedir/subDir1/foo.css"); 044 045 path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); 046 047 Assert.assertEquals("Path incorrect for same dir", "", path); 048 049 fromFile = new File("/basedir/dir1/subDir1/foo.css"); 050 toFile = new File("/basedir/dir2/subDir2/foo.css"); 051 052 path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); 053 054 Assert.assertEquals("Path incorrect for up two dir", "../../dir2/subDir2/", path); 055 056 fromFile = new File("/basedir/subDir1/foo.css"); 057 toFile = new File("/basedir/subDir1/moreDir/foo.css"); 058 059 path = ThemeBuilderUtils.calculatePathToFile(fromFile, toFile); 060 061 Assert.assertEquals("Path incorrect for sub dir", "moreDir/", path); 062 } 063 064 /** 065 * Tests the addition of a string to a string array 066 */ 067 @Test 068 public void testAddStringToArray() { 069 String[] array1 = new String[] {"a1", "a2"}; 070 String stringToAdd = "b1"; 071 072 String[] combinedArray = ThemeBuilderUtils.addToArray(array1, stringToAdd); 073 074 Assert.assertEquals("Combined array length is not correct", 3, combinedArray.length); 075 076 Assert.assertEquals("a1", combinedArray[0]); 077 Assert.assertEquals("a2", combinedArray[1]); 078 Assert.assertEquals("b1", combinedArray[2]); 079 } 080 081 /** 082 * Tests the addition of string arrays 083 */ 084 @Test 085 public void testAddArrayToArray() { 086 String[] array1 = new String[] {"a1", "a2"}; 087 String[] array2 = new String[] {"b1", "b2", "b3"}; 088 089 String[] combinedArray = ThemeBuilderUtils.addToArray(array1, array2); 090 091 Assert.assertEquals("Combined array length is not correct", 5, combinedArray.length); 092 093 Assert.assertEquals("a1", combinedArray[0]); 094 Assert.assertEquals("a2", combinedArray[1]); 095 Assert.assertEquals("b1", combinedArray[2]); 096 Assert.assertEquals("b2", combinedArray[3]); 097 Assert.assertEquals("b3", combinedArray[4]); 098 099 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}