01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 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.gui.swing.tree;
17:
18: // JUnit dependencies
19: import javax.swing.tree.TreeModel;
20: import junit.framework.Test;
21: import junit.framework.TestCase;
22: import junit.framework.TestSuite;
23: import org.geotools.metadata.AbstractMetadata;
24: import org.geotools.metadata.iso.citation.Citations;
25:
26: /**
27: * Tests {@link NamedTreeNode}, especially the part that instantiate them using Java reflection.
28: *
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/widgets-swing/src/test/java/org/geotools/gui/swing/tree/NamedTreeNodeTest.java $
30: * @version $Id: NamedTreeNodeTest.java 25175 2007-04-16 13:40:57Z desruisseaux $
31: * @author Martin Desruisseaux (Geomatys)
32: */
33: public class NamedTreeNodeTest extends TestCase {
34: /**
35: * Run the suit from the command line.
36: */
37: public static void main(final String[] args) {
38: junit.textui.TestRunner.run(suite());
39: }
40:
41: /**
42: * Returns the test suite.
43: */
44: public static Test suite() {
45: return new TestSuite(NamedTreeNodeTest.class);
46: }
47:
48: /**
49: * Constructs a test case with the given name.
50: */
51: public NamedTreeNodeTest(final String name) {
52: super (name);
53: }
54:
55: /**
56: * Verifies that {@link AbstractMetadata#asTree} uses instances of {@link NamedTreeNode}.
57: * Because those instances were created by Java reflection, the compiler will not detect
58: * broken link, so we need to check with this test case.
59: */
60: public void testCitations() {
61: final AbstractMetadata citation = (AbstractMetadata) Citations.EPSG;
62: final TreeModel tree = citation.asTree();
63: final Object root = tree.getRoot();
64: assertTrue(root instanceof javax.swing.tree.TreeNode);
65: assertTrue(root instanceof NamedTreeNode);
66: final TreeNode node = (TreeNode) root;
67: assertEquals("Citation", node.toString());
68: assertSame(citation, node.getUserObject());
69: }
70: }
|