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