svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libTools / src-test / org / gvsig / tools / locator / AbstractLocatorTest.java @ 23576
History | View | Annotate | Download (3.73 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Gobernment (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {{Company}} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.tools.locator; |
28 |
|
29 |
import java.util.Arrays; |
30 |
import java.util.Collection; |
31 |
import java.util.Map; |
32 |
|
33 |
import junit.framework.TestCase; |
34 |
|
35 |
/**
|
36 |
* Unit tests for the AbstractLocator class.
|
37 |
*
|
38 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
39 |
*/
|
40 |
public class AbstractLocatorTest extends TestCase { |
41 |
|
42 |
private TestLocator locator;
|
43 |
|
44 |
protected void setUp() throws Exception { |
45 |
super.setUp();
|
46 |
locator = new TestLocator();
|
47 |
} |
48 |
|
49 |
protected void tearDown() throws Exception { |
50 |
super.tearDown();
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* Test method for {@link org.gvsig.tools.locator.AbstractLocator#getNames()}.
|
55 |
*/
|
56 |
public void testGetNames() { |
57 |
assertNull("Empty locator must not return any names", locator
|
58 |
.getNames()); |
59 |
|
60 |
String name1 = "test1"; |
61 |
String name2 = "test2"; |
62 |
|
63 |
locator.register(name1, String.class);
|
64 |
locator.register(name2, String.class);
|
65 |
|
66 |
String[] names = locator.getNames(); |
67 |
|
68 |
assertEquals("Number of registered names incorrect, must be 2", 2, |
69 |
names.length); |
70 |
|
71 |
Collection namesColl = Arrays.asList(names); |
72 |
assertTrue("The list of names does not contain the registered name: "
|
73 |
+ name1, namesColl.contains(name1)); |
74 |
assertTrue("The list of names does not contain the registered name: "
|
75 |
+ name2, namesColl.contains(name2)); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Test method for
|
80 |
* {@link org.gvsig.tools.locator.AbstractLocator#get(java.lang.String)} and
|
81 |
* {@link org.gvsig.tools.locator.AbstractLocator#register(java.lang.String, java.lang.Class)}
|
82 |
*/
|
83 |
public void testGetAndRegisterClass() { |
84 |
Class clazz = String.class; |
85 |
String name = "test"; |
86 |
|
87 |
locator.register(name, clazz); |
88 |
|
89 |
Object ref = locator.get(name);
|
90 |
|
91 |
assertEquals(clazz, ref.getClass()); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Test method for
|
96 |
* {@link org.gvsig.tools.locator.AbstractLocator#get(java.lang.String)} and
|
97 |
* {@link org.gvsig.tools.locator.AbstractLocator#register(String, LocatorObjectFactory)
|
98 |
|
99 |
*/
|
100 |
public void testGetAndRegisterFactory() { |
101 |
final Object ref = new Object(); |
102 |
LocatorObjectFactory factory = new LocatorObjectFactory() {
|
103 |
|
104 |
public Object create() { |
105 |
return ref;
|
106 |
} |
107 |
|
108 |
public Object create(Object[] args) { |
109 |
return ref;
|
110 |
} |
111 |
|
112 |
public Object create(Map args) { |
113 |
return ref;
|
114 |
} |
115 |
}; |
116 |
|
117 |
String name = "test"; |
118 |
|
119 |
locator.register(name, factory); |
120 |
|
121 |
Object locatorRef = locator.get(name);
|
122 |
|
123 |
assertEquals(ref, locatorRef); |
124 |
} |
125 |
|
126 |
public class TestLocator extends AbstractLocator { |
127 |
public String getLocatorName() { |
128 |
return "TestLocator"; |
129 |
} |
130 |
} |
131 |
|
132 |
} |