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