01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2006-2007, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.factory;
17:
18: // JUnit dependencies
19: import junit.framework.Test;
20: import junit.framework.TestCase;
21: import junit.framework.TestSuite;
22:
23: /**
24: * Tests {@link AbstractFactory}.
25: *
26: * @since 2.3
27: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/factory/AbstractFactoryTest.java $
28: * @version $Id: AbstractFactoryTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
29: * @author Martin Desruisseaux
30: */
31: public final class AbstractFactoryTest extends TestCase {
32: /**
33: * Run the suite from the command line.
34: */
35: public static void main(String[] args) {
36: org.geotools.util.logging.Logging.GEOTOOLS
37: .forceMonolineConsoleOutput();
38: junit.textui.TestRunner.run(suite());
39: }
40:
41: /**
42: * Returns the test suite.
43: */
44: public static Test suite() {
45: return new TestSuite(AbstractFactoryTest.class);
46: }
47:
48: /**
49: * Constructs a test case.
50: */
51: public AbstractFactoryTest(final String testName) {
52: super (testName);
53: }
54:
55: /**
56: * Tests {@link AbstractFactory#equals}.
57: */
58: public void testEquals() {
59: final AbstractFactory f1 = new AbstractFactory();
60: final AbstractFactory f2 = new AbstractFactory();
61: final AbstractFactory f3 = new AbstractFactory();
62: f1.hints.put("Key 1", "Value 1");
63: f2.hints.put("Key 2", "Value 2");
64: f3.hints.put("Key 3 reference f1", f1);
65: f2.hints.put("Key 2 reference f3", f3);
66: f1.hints.put("Key 1 reference f2", f2);
67:
68: assertFalse(f1.toString().length() == 0);
69:
70: assertEquals(f1, f1);
71: assertEquals(f2, f2);
72: assertEquals(f3, f3);
73: assertFalse(f1.equals(f2)); // Different number of hints.
74: assertFalse(f1.equals(f3)); // Same number of hints, differerent key.
75: assertFalse(f2.equals(f3)); // Different number of hints.
76:
77: // Tests recursivity on a f2 --> f3 --> f1 --> f2 dependency graph.
78: final AbstractFactory f1b = new AbstractFactory();
79: final AbstractFactory f2b = new AbstractFactory();
80: final AbstractFactory f3b = new AbstractFactory();
81: f1b.hints.put("Key 1", "Value 1");
82: f2b.hints.put("Key 2", "Value 2");
83: f3b.hints.put("Key 3 reference f1", f1b);
84: f2b.hints.put("Key 2 reference f3", f3b);
85: f1b.hints.put("Key 1 reference f2", f2b);
86: assertEquals(f2, f2b);
87:
88: f1b.hints.put("Key 1", "Different value");
89: assertFalse(f2.equals(f2b));
90: }
91: }
|