1 15 package hivemind.test; 16 17 import org.apache.hivemind.Location; 18 import org.apache.hivemind.Resource; 19 import org.apache.hivemind.impl.LocationImpl; 20 import org.apache.hivemind.util.ClasspathResource; 21 22 27 public class TestLocation extends FrameworkTestCase 28 { 29 private final Resource _resource1 = new ClasspathResource(_resolver, "/somepackage/somefile"); 30 31 private final Resource _resource2 = new ClasspathResource(_resolver, 32 "/someotherpackage/someotherfile"); 33 34 private Resource _location = new ClasspathResource(null, "/META-INF/foo.bar"); 35 36 public void testNoNumbers() 37 { 38 LocationImpl l = new LocationImpl(_location); 39 40 assertSame(_location, l.getResource()); 41 assertTrue(l.getLineNumber() <= 0); 42 assertTrue(l.getColumnNumber() <= 0); 43 } 44 45 public void testToStringShort() 46 { 47 Location l = new LocationImpl(_location); 48 49 assertEquals("classpath:/META-INF/foo.bar", l.toString()); 50 } 51 52 public void testWithLine() 53 { 54 LocationImpl l = new LocationImpl(_location, 22); 55 56 assertEquals(22, l.getLineNumber()); 57 assertEquals("classpath:/META-INF/foo.bar, line 22", l.toString()); 58 } 59 60 public void testWithNumbers() 61 { 62 LocationImpl l = new LocationImpl(_location, 100, 15); 63 64 assertEquals(100, l.getLineNumber()); 65 assertEquals(15, l.getColumnNumber()); 66 } 67 68 public void testToStringLong() 69 { 70 Location l = new LocationImpl(_location, 97, 3); 71 72 assertEquals("classpath:/META-INF/foo.bar, line 97, column 3", l.toString()); 73 } 74 75 public void testEqualsBare() 76 { 77 Location l1 = new LocationImpl(_resource1); 78 79 assertEquals(true, l1.equals(new LocationImpl(_resource1))); 80 81 assertEquals(false, l1.equals(new LocationImpl(_resource2))); 82 assertEquals(false, l1.equals(new LocationImpl(_resource1, 10))); 83 } 84 85 public void testEqualsLineNo() 86 { 87 Location l1 = new LocationImpl(_resource1, 10); 88 89 assertEquals(true, l1.equals(new LocationImpl(_resource1, 10))); 90 assertEquals(false, l1.equals(new LocationImpl(_resource1, 11))); 91 assertEquals(false, l1.equals(new LocationImpl(_resource2, 10))); 92 assertEquals(false, l1.equals(new LocationImpl(_resource1, 10, 1))); 93 } 94 95 public void testEqualsFull() 96 { 97 Location l1 = new LocationImpl(_resource1, 10, 5); 98 99 assertEquals(true, l1.equals(new LocationImpl(_resource1, 10, 5))); 100 assertEquals(false, l1.equals(new LocationImpl(_resource1, 10, 6))); 101 assertEquals(false, l1.equals(new LocationImpl(_resource1, 11, 5))); 102 assertEquals(false, l1.equals(new LocationImpl(_resource2, 10, 5))); 103 } 104 105 public void testHashCodeBare() 106 { 107 Location l1 = new LocationImpl(_resource1); 108 Location l2 = new LocationImpl(_resource1); 109 110 assertEquals(l1.hashCode(), l2.hashCode()); 111 } 112 113 public void testHashCodeLineNo() 114 { 115 Location l1 = new LocationImpl(_resource1, 15); 116 Location l2 = new LocationImpl(_resource1, 15); 117 118 assertEquals(l1.hashCode(), l2.hashCode()); 119 } 120 121 public void testHashCodeFull() 122 { 123 Location l1 = new LocationImpl(_resource1, 15, 20); 124 Location l2 = new LocationImpl(_resource1, 15, 20); 125 126 assertEquals(l1.hashCode(), l2.hashCode()); 127 } 128 129 } | Popular Tags |