001: /*
002: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved.
004: $Id: TestLocators.java,v 1.3 2008/01/02 12:08:35 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.util.test;
008:
009: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
010: import com.hp.hpl.jena.util.*;
011:
012: public class TestLocators extends ModelTestBase {
013: private static final ClassLoader systemClassLoader = ClassLoader
014: .getSystemClassLoader();
015: private static final ClassLoader otherClassLoader = new ClassLoader() {
016: };
017:
018: public TestLocators(String name) {
019: super (name);
020: }
021:
022: public void testClassLoaderLocatorEquality() {
023: Locator A1 = new LocatorClassLoader(systemClassLoader);
024: Locator A2 = new LocatorClassLoader(systemClassLoader);
025: Locator B = new LocatorClassLoader(otherClassLoader);
026: testLocatorEquality(A1, A2, B);
027: }
028:
029: /**
030: A1 and A2 should be equal, but both different from B.
031: */
032: private void testLocatorEquality(Locator A1, Locator A2, Locator B) {
033: assertEquals(A1, A1);
034: assertEquals(A2, A2);
035: assertEquals(A1, A2);
036: assertEquals(A2, A1);
037: assertEquals(B, B);
038: assertDiffer(A1, B);
039: assertDiffer(B, A1);
040: }
041:
042: public void testClassLoaderLocatorHashcode() {
043: assertEquals(systemClassLoader.hashCode(),
044: new LocatorClassLoader(systemClassLoader).hashCode());
045: assertEquals(otherClassLoader.hashCode(),
046: new LocatorClassLoader(otherClassLoader).hashCode());
047: }
048:
049: public void testLocatorFileEquality() {
050: Locator A1 = new LocatorFile("foo/bar");
051: Locator A2 = new LocatorFile("foo/bar");
052: Locator B = new LocatorFile("bill/ben");
053: testLocatorEquality(A1, A2, B);
054: }
055:
056: public void testLocatorFileHashcode() {
057: testLocatorFileHashCode("foo/bar");
058: testLocatorFileHashCode("bill/ben");
059: testLocatorFileHashCode("another/night");
060: }
061:
062: private void testLocatorFileHashCode(String dirName) {
063: assertEquals(dirName.hashCode(), new LocatorFile(dirName)
064: .hashCode());
065: }
066:
067: public void testLocatorURLEquality() {
068: Locator A1 = new LocatorURL();
069: Locator A2 = new LocatorURL();
070: assertEquals(A1, A2);
071: assertDiffer(A1, "");
072: }
073:
074: /**
075: There all equal. Pick a value that will at least be discriminating among
076: other types (so `0` isn't a good answer).
077: */
078: public void testLocatorURLHashcode() {
079: assertEquals(LocatorURL.class.hashCode(), new LocatorURL()
080: .hashCode());
081: }
082: }
083:
084: /*
085: * (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
086: * All rights reserved.
087: *
088: * Redistribution and use in source and binary forms, with or without
089: * modification, are permitted provided that the following conditions
090: * are met:
091: * 1. Redistributions of source code must retain the above copyright
092: * notice, this list of conditions and the following disclaimer.
093: * 2. Redistributions in binary form must reproduce the above copyright
094: * notice, this list of conditions and the following disclaimer in the
095: * documentation and/or other materials provided with the distribution.
096: * 3. The name of the author may not be used to endorse or promote products
097: * derived from this software without specific prior written permission.
098: *
099: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109: */
|