1 15 package org.apache.hivemind.util; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import java.util.Locale ; 20 21 import org.apache.hivemind.util.ClasspathResource; 22 import org.apache.hivemind.Resource; 23 24 29 public class TestClasspathResource extends FrameworkTestCase 30 { 31 32 public void testClasspathEquals() 33 { 34 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 35 Resource l2 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 36 37 assertEquals("Object equality.", l1, l2); 38 39 assertEquals("Hash code", l1.hashCode(), l2.hashCode()); 40 } 41 42 public void testClasspathRelativeSameResource() 43 { 44 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz"); 45 Resource l2 = l1.getRelativeResource("Baz"); 46 47 assertSame(l1, l2); 48 } 49 50 public void testClasspathRelativeSameFolder() 51 { 52 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz"); 53 Resource expected = new ClasspathResource(_resolver, "/foo/bar/Fubar"); 54 Resource actual = l1.getRelativeResource("Fubar"); 55 56 assertEquals(expected, actual); 57 } 58 59 public void testClasspathRelative() 60 { 61 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz"); 62 Resource expected = new ClasspathResource(_resolver, "/foo/bar/gloop/Yup"); 63 Resource actual = l1.getRelativeResource("gloop/Yup"); 64 65 assertEquals(expected, actual); 66 } 67 68 public void testClasspathAbsolute() 69 { 70 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz"); 71 Resource expected = new ClasspathResource(_resolver, "/bip/bop/Boop"); 72 Resource actual = l1.getRelativeResource("/bip/bop/Boop"); 73 74 assertEquals(expected, actual); 75 } 76 77 public void testClasspathLocalize() 78 { 79 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 80 Resource expected = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home_fr.png"); 81 Resource actual = l1.getLocalization(Locale.FRANCE); 82 83 assertEquals(expected, actual); 84 } 85 86 public void testClasspathLocalizeMissing() 87 { 88 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz.zap"); 89 90 Resource l2 = l1.getLocalization(Locale.ENGLISH); 91 92 assertNull(l2); 93 } 94 95 public void testClasspathLocalizeDefault() 96 { 97 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 98 Resource actual = l1.getLocalization(Locale.KOREAN); 99 100 assertSame(l1, actual); 101 } 102 103 public void testClasspathLocalizeNull() 104 { 105 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 106 Resource actual = l1.getLocalization(null); 107 108 assertSame(l1, actual); 109 } 110 111 public void testEqualsNull() 112 { 113 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/home.png"); 114 115 assertTrue(!l1.equals(null)); 116 } 117 118 public void testClasspathRelativeSamePath() 119 { 120 Resource l1 = new ClasspathResource(_resolver, "/foo/bar/Baz"); 121 Resource l2 = l1.getRelativeResource("/foo/bar/Baz"); 122 123 assertSame(l1, l2); 124 } 125 126 public void testTrailingSlash() 127 { 128 Resource l1 = new ClasspathResource(_resolver, "/"); 129 Resource expected = new ClasspathResource(_resolver, "/foo"); 130 Resource actual = l1.getRelativeResource("foo"); 131 132 assertEquals(expected, actual); 133 } 134 135 public void testLocalizeExtensionless() 136 { 137 Resource l1 = new ClasspathResource(_resolver, "/org/apache/hivemind/util/empty"); 138 Resource expected = new ClasspathResource(_resolver, "/org/apache/hivemind/util/empty_fr"); 139 Resource actual = l1.getLocalization(Locale.FRENCH); 140 141 assertEquals(expected, actual); 142 } 143 } 144 | Popular Tags |