001: // Copyright 2004, 2005 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package hivemind.test;
016:
017: import org.apache.hivemind.Location;
018: import org.apache.hivemind.Resource;
019: import org.apache.hivemind.impl.LocationImpl;
020: import org.apache.hivemind.util.ClasspathResource;
021:
022: /**
023: * Test the {@link org.apache.hivemind.impl.LocationImpl} class.
024: *
025: * @author Howard Lewis Ship
026: */
027: public class TestLocation extends FrameworkTestCase {
028: private final Resource _resource1 = new ClasspathResource(
029: _resolver, "/somepackage/somefile");
030:
031: private final Resource _resource2 = new ClasspathResource(
032: _resolver, "/someotherpackage/someotherfile");
033:
034: private Resource _location = new ClasspathResource(null,
035: "/META-INF/foo.bar");
036:
037: public void testNoNumbers() {
038: Location l = new LocationImpl(_location);
039:
040: assertSame(_location, l.getResource());
041: assertTrue(l.getLineNumber() <= 0);
042: assertTrue(l.getColumnNumber() <= 0);
043: }
044:
045: public void testToStringShort() {
046: Location l = new LocationImpl(_location);
047:
048: assertEquals("classpath:/META-INF/foo.bar", l.toString());
049: }
050:
051: public void testWithLine() {
052: Location l = new LocationImpl(_location, 22);
053:
054: assertEquals(22, l.getLineNumber());
055: assertEquals("classpath:/META-INF/foo.bar, line 22", l
056: .toString());
057: }
058:
059: public void testWithNumbers() {
060: Location l = new LocationImpl(_location, 100, 15);
061:
062: assertEquals(100, l.getLineNumber());
063: assertEquals(15, l.getColumnNumber());
064: }
065:
066: public void testToStringLong() {
067: Location l = new LocationImpl(_location, 97, 3);
068:
069: assertEquals("classpath:/META-INF/foo.bar, line 97, column 3",
070: l.toString());
071: }
072:
073: public void testEqualsBare() {
074: Location l1 = new LocationImpl(_resource1);
075:
076: assertEquals(true, l1.equals(new LocationImpl(_resource1)));
077:
078: assertEquals(false, l1.equals(new LocationImpl(_resource2)));
079: assertEquals(false, l1.equals(new LocationImpl(_resource1, 10)));
080: }
081:
082: public void testEqualsLineNo() {
083: Location l1 = new LocationImpl(_resource1, 10);
084:
085: assertEquals(true, l1.equals(new LocationImpl(_resource1, 10)));
086: assertEquals(false, l1.equals(new LocationImpl(_resource1, 11)));
087: assertEquals(false, l1.equals(new LocationImpl(_resource2, 10)));
088: assertEquals(false, l1.equals(new LocationImpl(_resource1, 10,
089: 1)));
090: }
091:
092: public void testEqualsFull() {
093: Location l1 = new LocationImpl(_resource1, 10, 5);
094:
095: assertEquals(true, l1
096: .equals(new LocationImpl(_resource1, 10, 5)));
097: assertEquals(false, l1.equals(new LocationImpl(_resource1, 10,
098: 6)));
099: assertEquals(false, l1.equals(new LocationImpl(_resource1, 11,
100: 5)));
101: assertEquals(false, l1.equals(new LocationImpl(_resource2, 10,
102: 5)));
103: }
104:
105: public void testHashCodeBare() {
106: Location l1 = new LocationImpl(_resource1);
107: Location l2 = new LocationImpl(_resource1);
108:
109: assertEquals(l1.hashCode(), l2.hashCode());
110: }
111:
112: public void testHashCodeLineNo() {
113: Location l1 = new LocationImpl(_resource1, 15);
114: Location l2 = new LocationImpl(_resource1, 15);
115:
116: assertEquals(l1.hashCode(), l2.hashCode());
117: }
118:
119: public void testHashCodeFull() {
120: Location l1 = new LocationImpl(_resource1, 15, 20);
121: Location l2 = new LocationImpl(_resource1, 15, 20);
122:
123: assertEquals(l1.hashCode(), l2.hashCode());
124: }
125:
126: }
|