root / branches / v2_0_0_prep / libraries / libFMap_dal / src-test / org / gvsig / fmap / dal / feature / impl / DefaultFeatureSelectionTest.java @ 24497
History | View | Annotate | Download (6.37 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 {DiSiD Technologies} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.fmap.dal.feature.impl; |
28 |
|
29 |
import junit.framework.TestCase; |
30 |
|
31 |
import org.easymock.MockControl; |
32 |
import org.gvsig.fmap.dal.feature.*; |
33 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection; |
34 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureStore; |
35 |
|
36 |
/**
|
37 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
38 |
*/
|
39 |
public class DefaultFeatureSelectionTest extends TestCase { |
40 |
private FeatureSelection selection;
|
41 |
private MockControl refControl1;
|
42 |
private FeatureReference ref1;
|
43 |
private MockControl refControl2;
|
44 |
private FeatureReference ref2;
|
45 |
private MockControl fControl1;
|
46 |
private Feature feature1;
|
47 |
private MockControl fControl2;
|
48 |
private Feature feature2;
|
49 |
private MockControl storeControl;
|
50 |
private DefaultFeatureStore store;
|
51 |
private MockControl fsetControl;
|
52 |
private FeatureSet featureSet;
|
53 |
|
54 |
private int total = 10; |
55 |
|
56 |
protected void setUp() throws Exception { |
57 |
super.setUp();
|
58 |
refControl1 = MockControl.createNiceControl(FeatureReference.class); |
59 |
ref1 = (FeatureReference) refControl1.getMock(); |
60 |
refControl2 = MockControl.createNiceControl(FeatureReference.class); |
61 |
ref2 = (FeatureReference) refControl2.getMock(); |
62 |
|
63 |
fControl1 = MockControl.createControl(Feature.class); |
64 |
feature1 = (Feature) fControl1.getMock(); |
65 |
fControl2 = MockControl.createControl(Feature.class); |
66 |
feature2 = (Feature) fControl2.getMock(); |
67 |
|
68 |
storeControl = MockControl.createNiceControl(DefaultFeatureStore.class); |
69 |
store = (DefaultFeatureStore) storeControl.getMock(); |
70 |
|
71 |
fsetControl = MockControl.createNiceControl(FeatureSet.class); |
72 |
featureSet = (FeatureSet) fsetControl.getMock(); |
73 |
|
74 |
storeControl.expectAndReturn(store.getFeatureSet(), featureSet); |
75 |
fsetControl.expectAndReturn(featureSet.getSize(), total); |
76 |
|
77 |
storeControl.replay(); |
78 |
fsetControl.replay(); |
79 |
|
80 |
selection = new DefaultFeatureSelection(store);
|
81 |
} |
82 |
|
83 |
protected void tearDown() throws Exception { |
84 |
super.tearDown();
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Test method for
|
89 |
* {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#select(org.gvsig.fmap.dal.feature.Feature)}
|
90 |
* .
|
91 |
*/
|
92 |
public void testSelectFeature() { |
93 |
fControl1.expectAndReturn(feature1.getReference(), ref1, 2);
|
94 |
fControl2.expectAndReturn(feature2.getReference(), ref2, 3);
|
95 |
fControl1.replay(); |
96 |
fControl2.replay(); |
97 |
|
98 |
// Add a feature
|
99 |
selection.select(feature1); |
100 |
assertTrue("Selected feature1 is not recognized as selected", selection
|
101 |
.isSelected(feature1)); |
102 |
assertFalse("Selected feature2 is recognized as selected", selection
|
103 |
.isSelected(feature2)); |
104 |
|
105 |
selection.select(feature2); |
106 |
assertTrue(selection.isSelected(feature2)); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Test method for
|
111 |
* {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#deselect(org.gvsig.fmap.dal.feature.Feature)}
|
112 |
* .
|
113 |
*/
|
114 |
public void testDeselectFeature() { |
115 |
fControl1.expectAndReturn(feature1.getReference(), ref1, 3);
|
116 |
fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
|
117 |
fControl1.replay(); |
118 |
fControl2.replay(); |
119 |
|
120 |
// Remove a feature
|
121 |
selection.select(feature1); |
122 |
selection.select(feature2); |
123 |
assertTrue(selection.isSelected(feature2)); |
124 |
selection.deselect(feature2); |
125 |
assertFalse(selection.isSelected(feature2)); |
126 |
selection.deselect(feature1); |
127 |
assertFalse(selection.isSelected(feature1)); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Test method for
|
132 |
* {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#getSize()}
|
133 |
* .
|
134 |
*/
|
135 |
public void testGetSize() throws Exception { |
136 |
fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
|
137 |
fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
|
138 |
fControl1.replay(); |
139 |
fControl2.replay(); |
140 |
|
141 |
// None selected
|
142 |
assertEquals(0, selection.getSize());
|
143 |
selection.select(feature1); |
144 |
selection.select(feature2); |
145 |
// Two selected
|
146 |
assertEquals(2, selection.getSize());
|
147 |
// Deselect one, so one left selected
|
148 |
selection.deselect(feature2); |
149 |
assertEquals(1, selection.getSize());
|
150 |
// Reverse the selection, so all buy one selected
|
151 |
selection.reverse(); |
152 |
assertEquals(total - 1, selection.getSize());
|
153 |
// Deselect another one, so all but two selected
|
154 |
selection.deselect(feature2); |
155 |
assertEquals(total - 2, selection.getSize());
|
156 |
// Deselect an already deselected one, nothing changes
|
157 |
selection.deselect(feature2); |
158 |
assertEquals(total - 2, selection.getSize());
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Test method for
|
163 |
* {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#isEmpty()}
|
164 |
* .
|
165 |
*/
|
166 |
public void testIsEmpty() throws Exception { |
167 |
fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
|
168 |
fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
|
169 |
fControl1.replay(); |
170 |
fControl2.replay(); |
171 |
|
172 |
// None selected
|
173 |
assertTrue(selection.isEmpty()); |
174 |
|
175 |
// One selected
|
176 |
selection.select(feature1); |
177 |
assertFalse(selection.isEmpty()); |
178 |
|
179 |
// Deselect all
|
180 |
selection.deselectAll(); |
181 |
assertTrue(selection.isEmpty()); |
182 |
|
183 |
// Reverse
|
184 |
selection.reverse(); |
185 |
assertFalse(selection.isEmpty()); |
186 |
} |
187 |
|
188 |
} |