01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library 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 GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.memory;
17:
18: import java.util.Arrays;
19: import java.util.Iterator;
20:
21: import org.geotools.data.DataTestCase;
22: import org.geotools.feature.FeatureCollection;
23:
24: public class MemoryFeatureCollectionTest extends DataTestCase {
25: private MemoryFeatureCollection roads;
26:
27: public MemoryFeatureCollectionTest(String test) {
28: super (test);
29: }
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33: roads = new MemoryFeatureCollection(roadType);
34: roads.addAll(Arrays.asList(roadFeatures));
35: }
36:
37: public void testAdd() {
38: MemoryFeatureCollection rivers = new MemoryFeatureCollection(
39: riverType);
40: for (int i = 0; i < riverFeatures.length; i++) {
41: rivers.add(riverFeatures[i]);
42: }
43: assertEquals(riverFeatures.length, rivers.size());
44: }
45:
46: public void testAddAll() {
47: MemoryFeatureCollection rivers = new MemoryFeatureCollection(
48: riverType);
49: rivers.addAll(Arrays.asList(riverFeatures));
50: }
51:
52: public void testSize() {
53: assertEquals(roadFeatures.length, roads.size());
54: }
55:
56: public void testResources() {
57: Object[] array = roads.toArray();
58: roads.purge();
59: assertEquals(roads.size(), array.length);
60:
61: Iterator i = roads.iterator();
62: assertTrue(i.hasNext());
63: roads.close(i);
64: try {
65: assertFalse(i.hasNext());
66: fail("should be closed");
67: } catch (IllegalStateException closed) {
68: }
69:
70: i = roads.iterator();
71: assertTrue(i.hasNext());
72: roads.purge();
73: try {
74: assertFalse(i.hasNext());
75: fail("should be closed");
76: } catch (IllegalStateException closed) {
77: }
78: }
79:
80: public void testSubCollection() {
81: FeatureCollection sub = roads.subCollection(rd12Filter);
82: assertEquals(2, sub.size());
83: }
84:
85: public void testSubSubCollection() {
86: FeatureCollection sub = roads.subCollection(rd12Filter);
87: FeatureCollection subsub = sub.subCollection(rd1Filter);
88: assertEquals(1, subsub.size());
89: }
90:
91: public void XtestSort() {
92: // FeatureList fList = roads.sort(SortBy.NATURAL_ORDER);
93: // for (Object obj : fList) {
94: // System.out.println(obj);
95: // }
96: }
97: }
|