Statistics
| Revision:

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 @ 40559

History | View | Annotate | Download (7.34 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
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.fmap.dal.feature.impl;
29

    
30
import org.easymock.MockControl;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureReference;
33
import org.gvsig.fmap.dal.feature.FeatureSelection;
34
import org.gvsig.fmap.dal.feature.FeatureSet;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
38

    
39
/**
40
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
41
 */
42
public class DefaultFeatureSelectionTest extends AbstractLibraryAutoInitTestCase {
43
    private FeatureSelection selection;
44
    private MockControl refControl1;
45
    private FeatureReference ref1;
46
    private MockControl refControl2;
47
    private FeatureReference ref2;
48
    private MockControl fControl1;
49
    private Feature feature1;
50
    private MockControl fControl2;
51
    private Feature feature2;
52
    private MockControl storeControl;
53
    private FeatureType featureType;
54
    private MockControl fTypeControl;
55
    private FeatureStore store;
56
    private MockControl fsetControl;
57
    private FeatureSet featureSet;
58
    private MockControl helperControl;
59
    private FeatureSelectionHelper helper;
60

    
61
    private int total = 10;
62

    
63
    protected void doSetUp() throws Exception { 
64
        refControl1 = MockControl.createNiceControl(FeatureReference.class);
65
        ref1 = (FeatureReference) refControl1.getMock();
66
        refControl2 = MockControl.createNiceControl(FeatureReference.class);
67
        ref2 = (FeatureReference) refControl2.getMock();
68

    
69
        fControl1 = MockControl.createControl(Feature.class);
70
        feature1 = (Feature) fControl1.getMock();
71
        fControl2 = MockControl.createControl(Feature.class);
72
        feature2 = (Feature) fControl2.getMock();
73

    
74
        fTypeControl = MockControl.createNiceControl(FeatureType.class);
75
        featureType = (FeatureType) fTypeControl.getMock();
76

    
77
        fControl1.expectAndDefaultReturn(feature1.getType(), featureType);
78
        fControl2.expectAndDefaultReturn(feature2.getType(), featureType);
79

    
80
        storeControl = MockControl.createNiceControl(FeatureStore.class);
81
        store = (FeatureStore) storeControl.getMock();
82
        storeControl.expectAndReturn(store.getFeatureCount(), total);
83

    
84
        helperControl = MockControl
85
                .createNiceControl(FeatureSelectionHelper.class);
86
        helper = (FeatureSelectionHelper) helperControl.getMock();
87
        helperControl.expectAndDefaultReturn(helper.getFeatureStoreDeltaSize(),
88
                0);
89

    
90
        fsetControl = MockControl.createNiceControl(FeatureSet.class);
91
        featureSet = (FeatureSet) fsetControl.getMock();
92

    
93
        storeControl.expectAndReturn(store.getFeatureSet(), featureSet);
94
        fsetControl.expectAndReturn(featureSet.getSize(), total);
95

    
96
        storeControl.replay();
97
        fsetControl.replay();
98
        helperControl.replay();
99

    
100
        selection = new DefaultFeatureSelection(store, helper);
101
    }
102

    
103
    protected void tearDown() throws Exception {
104
        super.tearDown();
105
    }
106

    
107
    /**
108
     * Test method for
109
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#select(org.gvsig.fmap.dal.feature.Feature)}
110
     * .
111
     */
112
    public void testSelectFeature() {
113
        fControl1.expectAndReturn(feature1.getReference(), ref1, 2);
114
        fControl2.expectAndReturn(feature2.getReference(), ref2, 3);
115
        fControl1.replay();
116
        fControl2.replay();
117

    
118
        // Add a feature
119
        selection.select(feature1);
120
        assertTrue("Selected feature1 is not recognized as selected", selection
121
                .isSelected(feature1));
122
        assertFalse("Selected feature2 is recognized as selected", selection
123
                .isSelected(feature2));
124

    
125
        selection.select(feature2);
126
        assertTrue(selection.isSelected(feature2));
127
    }
128

    
129
    /**
130
     * Test method for
131
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#deselect(org.gvsig.fmap.dal.feature.Feature)}
132
     * .
133
     */
134
    public void testDeselectFeature() {
135
        fControl1.expectAndReturn(feature1.getReference(), ref1, 3);
136
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
137
        fControl1.replay();
138
        fControl2.replay();
139

    
140
        // Remove a feature
141
        selection.select(feature1);
142
        selection.select(feature2);
143
        assertTrue(selection.isSelected(feature2));
144
        selection.deselect(feature2);
145
        assertFalse(selection.isSelected(feature2));
146
        selection.deselect(feature1);
147
        assertFalse(selection.isSelected(feature1));
148
    }
149

    
150
    /**
151
     * Test method for
152
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#getSize()}
153
     * .
154
     */
155
    public void testGetSize() throws Exception {
156
        fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
157
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
158
        fControl1.replay();
159
        fControl2.replay();
160

    
161
        // None selected
162
        assertEquals(0, selection.getSize());
163
        selection.select(feature1);
164
        selection.select(feature2);
165
        // Two selected
166
        assertEquals(2, selection.getSize());
167
        // Deselect one, so one left selected
168
        selection.deselect(feature2);
169
        assertEquals(1, selection.getSize());
170
        // Reverse the selection, so all buy one selected
171
        selection.reverse();
172
        assertEquals(total - 1, selection.getSize());
173
        // Deselect another one, so all but two selected
174
        selection.deselect(feature2);
175
        assertEquals(total - 2, selection.getSize());
176
        // Deselect an already deselected one, nothing changes
177
        selection.deselect(feature2);
178
        assertEquals(total - 2, selection.getSize());
179
    }
180

    
181
    /**
182
     * Test method for
183
     * {@link org.gvsig.fmap.dal.feature.impl.DefaultFeatureSelection#isEmpty()}
184
     * .
185
     */
186
    public void testIsEmpty() throws Exception {
187
        fControl1.expectAndReturn(feature1.getReference(), ref1, 1);
188
        fControl2.expectAndReturn(feature2.getReference(), ref2, 4);
189
        fControl1.replay();
190
        fControl2.replay();
191

    
192
        // None selected
193
        assertTrue(selection.isEmpty());
194

    
195
        // One selected
196
        selection.select(feature1);
197
        assertFalse(selection.isEmpty());
198

    
199
        // Deselect all
200
        selection.deselectAll();
201
        assertTrue(selection.isEmpty());
202

    
203
        // Reverse
204
        selection.reverse();
205
        assertFalse(selection.isEmpty());
206
    }
207

    
208
}