Skip to content
Browse files

Migrate all shapefile tests to junit 4

  • Loading branch information...
1 parent 37935ee commit c951a6164969143730a33ef005b5584e24266b14 @aaime aaime committed Apr 7, 2013
Showing with 255 additions and 228 deletions.
  1. +20 −14 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/DbaseFileTest.java
  2. +5 −3 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/DbaseNullSupportTest.java
  3. +5 −5 ...les/plugin/shapefile/src/test/java/org/geotools/data/shapefile/DuplicateColumnNameReaderTest.java
  4. +6 −6 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ServiceTest.java
  5. +4 −6 ...les/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreFactoryTest.java
  6. +18 −14 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java
  7. +4 −8 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileNullHandlingTest.java
  8. +8 −13 ...es/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileQuadTreeReadWriteTest.java
  9. +10 −7 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileReadWriteTest.java
  10. +21 −9 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileTest.java
  11. +11 −3 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFileTypesTest.java
  12. +17 −11 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesLockingTest.java
  13. +17 −4 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesTest.java
  14. +23 −7 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesTestStream.java
  15. +13 −7 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/StorageFileTest.java
  16. +6 −11 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/TestCaseSupport.java
  17. +3 −20 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FIDTestCase.java
  18. +3 −10 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FidIndexerTest.java
  19. +13 −12 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FidQueryTest.java
  20. +18 −10 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/IndexedFidReaderTest.java
  21. +12 −19 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/IndexedFidWriterTest.java
  22. +5 −10 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/shp/PolygonHandler2Test.java
  23. +5 −11 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/shp/PolygonHandlerTest.java
  24. +8 −8 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/shp/xml/ShpXmlFileReaderTest.java
View
34 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/DbaseFileTest.java
@@ -16,20 +16,26 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.nio.charset.Charset;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.geotools.TestData;
-import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.dbf.DbaseFileHeader;
import org.geotools.data.shapefile.dbf.DbaseFileReader;
import org.geotools.data.shapefile.dbf.DbaseFileWriter;
import org.geotools.data.shapefile.files.ShpFiles;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
*
@@ -51,36 +57,31 @@
private ShpFiles shpFiles;
- public DbaseFileTest(String testName) throws IOException {
- super(testName);
- }
-
- public static void main(String[] args) {
- // verbose = true;
- junit.textui.TestRunner.run(suite(DbaseFileTest.class));
- }
-
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
shpFiles = new ShpFiles(TestData.url(TEST_FILE));
dbf = new DbaseFileReader(shpFiles, false,
ShapefileDataStore.DEFAULT_STRING_CHARSET);
}
+ @Test
public void testNumberofColsLoaded() {
assertEquals("Number of attributes found incorect", 252, dbf
.getHeader().getNumFields());
}
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
dbf.close();
super.tearDown();
}
+ @Test
public void testNumberofRowsLoaded() {
assertEquals("Number of rows", 49, dbf.getHeader().getNumRecords());
}
+ @Test
public void testDataLoaded() throws Exception {
Object[] attrs = new Object[dbf.getHeader().getNumFields()];
dbf.readEntry(attrs);
@@ -89,6 +90,7 @@ public void testDataLoaded() throws Exception {
((Double) attrs[4]).doubleValue(), 0.001);
}
+ @Test
public void testRowVsEntry() throws Exception {
Object[] attrs = new Object[dbf.getHeader().getNumFields()];
DbaseFileReader dbf2 = new DbaseFileReader(shpFiles, false,
@@ -105,6 +107,7 @@ public void testRowVsEntry() throws Exception {
dbf2.close();
}
+ @Test
public void testHeader() throws Exception {
DbaseFileHeader header = new DbaseFileHeader();
@@ -130,6 +133,7 @@ public void testHeader() throws Exception {
}
}
+ @Test
public void testAddColumn() throws Exception {
DbaseFileHeader header = new DbaseFileHeader();
@@ -149,6 +153,7 @@ public void testAddColumn() throws Exception {
}
}
+ @Test
public void testEmptyFields() throws Exception {
DbaseFileHeader header = new DbaseFileHeader();
header.addColumn("emptyString", 'C', 20, 0);
@@ -181,6 +186,7 @@ public void testEmptyFields() throws Exception {
f.delete();
}
+ @Test
public void testFieldFormatter() throws Exception {
DbaseFileWriter.FieldFormatter formatter = new DbaseFileWriter.FieldFormatter(Charset.defaultCharset(), TimeZone.getDefault());
View
8 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/DbaseNullSupportTest.java
@@ -1,5 +1,7 @@
package org.geotools.data.shapefile;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -12,11 +14,10 @@
import java.util.Date;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
import org.geotools.data.shapefile.dbf.DbaseFileHeader;
import org.geotools.data.shapefile.dbf.DbaseFileReader;
import org.geotools.data.shapefile.dbf.DbaseFileWriter;
+import org.junit.Test;
/**
* Verifies that null String, Date, Boolean, Integer, Long, Float, and Double
@@ -29,7 +30,7 @@
*
* @source $URL$
*/
-public class DbaseNullSupportTest extends TestCase {
+public class DbaseNullSupportTest {
/** declare a specific charset for test portability */
private static final Charset cs;
private static final TimeZone tz;
@@ -60,6 +61,7 @@
public static void main(String[] args) throws IOException {
new DbaseNullSupportTest().testNulls();
}
+ @Test
public void testNulls() throws IOException {
File tmp = File.createTempFile("test", ".dbf");
if (!tmp.delete()) {
View
10 ...in/shapefile/src/test/java/org/geotools/data/shapefile/DuplicateColumnNameReaderTest.java
@@ -1,5 +1,7 @@
package org.geotools.data.shapefile;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -8,11 +10,11 @@
import org.geotools.TestData;
import org.geotools.data.DataUtilities;
import org.geotools.data.Query;
-import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.factory.CommonFactoryFinder;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
@@ -33,10 +35,7 @@
public final Integer expectedValue = new Integer(20);
- public DuplicateColumnNameReaderTest(String name) throws IOException {
- super(name);
- }
-
+ @Test
public void testAttributeReader() throws IOException {
URL u = TestData.url(TestCaseSupport.class, SHPFILE);
File shpFile = DataUtilities.urlToFile(u);
@@ -57,6 +56,7 @@ public void testAttributeReader() throws IOException {
store.dispose();
}
+ @Test
public void testAttributeReaderIndexed() throws IOException {
URL u = TestData.url(TestCaseSupport.class, SHPFILE);
File shpFile = DataUtilities.urlToFile(u);
View
12 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ServiceTest.java
@@ -16,15 +16,16 @@
*/
package org.geotools.data.shapefile;
-import java.io.IOException;
+import static org.junit.Assert.*;
+
import java.util.HashMap;
import java.util.Iterator;
import org.geotools.TestData;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFactorySpi;
import org.geotools.data.DataStoreFinder;
-import org.geotools.data.shapefile.ShapefileDataStoreFactory;
+import org.junit.Test;
/**
*
@@ -38,13 +39,10 @@
final String TEST_FILE = "shapes/statepop.shp";
- public ServiceTest(String testName) throws IOException {
- super(testName);
- }
-
/**
* Make sure that the loading mechanism is working properly.
*/
+ @Test
public void testIsAvailable() {
Iterator list = DataStoreFinder.getAvailableDataStores();
boolean found = false;
@@ -62,6 +60,7 @@ public void testIsAvailable() {
/**
* Ensure that we can create a DataStore using url OR string url.
*/
+ @Test
public void testShapefileDataStore() throws Exception {
HashMap params = new HashMap();
params.put("url", TestData.url(TEST_FILE));
@@ -72,6 +71,7 @@ public void testShapefileDataStore() throws Exception {
ds.dispose();
}
+ @Test
public void testBadURL() {
HashMap params = new HashMap();
params.put("url", "aaa://bbb.ccc");
View
10 ...in/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreFactoryTest.java
@@ -19,9 +19,9 @@
import static org.geotools.data.shapefile.ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX;
import static org.geotools.data.shapefile.ShapefileDataStoreFactory.FSTYPE;
import static org.geotools.data.shapefile.ShapefileDataStoreFactory.URLP;
+import static org.junit.Assert.*;
import java.io.File;
-import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.util.HashMap;
@@ -32,6 +32,7 @@
import org.geotools.data.QueryCapabilities;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.util.KVP;
+import org.junit.After;
import org.junit.Test;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.Name;
@@ -49,11 +50,8 @@
private ShapefileDataStore store = null;
private ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
- public ShapefileDataStoreFactoryTest(String testName) throws IOException {
- super(testName);
- }
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if(store != null) {
store.dispose();
}
View
32 ...es/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileDataStoreTest.java
@@ -16,6 +16,14 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
@@ -46,7 +54,6 @@
import org.geotools.TestData;
import org.geotools.data.DataStore;
import org.geotools.data.DataUtilities;
-import org.geotools.data.DefaultQuery;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureReader;
import org.geotools.data.FeatureWriter;
@@ -67,6 +74,7 @@
import org.geotools.filter.IllegalFilterException;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
+import org.junit.After;
import org.junit.Test;
import org.opengis.feature.Feature;
import org.opengis.feature.FeatureVisitor;
@@ -114,12 +122,8 @@
.getFilterFactory2(null);
private ShapefileDataStore store;
- public ShapefileDataStoreTest(String testName) throws IOException {
- super(testName);
- }
-
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if(store != null) {
store.dispose();
}
@@ -149,7 +153,7 @@ protected SimpleFeatureCollection loadLocalFeaturesM2() throws IOException {
protected SimpleFeatureCollection loadFeatures(String resource, Charset charset,
Query q) throws Exception {
if (q == null)
- q = new DefaultQuery();
+ q = new Query();
URL url = TestData.url(resource);
store = new ShapefileDataStore(url);
store.setCharset(charset);
@@ -1171,7 +1175,7 @@ public void testGetReaderOptimizations() throws Exception {
ShapefileDataStore s = new ShapefileDataStore(url);
// attributes other than geometry can be ignored here
- Query query = new DefaultQuery(s.getSchema().getTypeName(),
+ Query query = new Query(s.getSchema().getTypeName(),
Filter.INCLUDE, new String[] { "the_geom" });
FeatureReader<SimpleFeatureType, SimpleFeature> reader = s.getFeatureReader(query, Transaction.AUTO_COMMIT);
assertEquals(1, reader.getFeatureType().getAttributeCount());
@@ -1190,7 +1194,7 @@ public void testGetReaderOptimizations() throws Exception {
.getEnvelopeInternal(), null);
Filter gf = ff.bbox(ff.property("the_geom"), bounds);
- query = new DefaultQuery(s.getSchema().getTypeName(), gf,
+ query = new Query(s.getSchema().getTypeName(), gf,
new String[] { "the_geom" });
reader.close();
@@ -1205,7 +1209,7 @@ public void testGetReaderOptimizations() throws Exception {
// file please
Filter cf = ff
.equals(ff.property("STATE_NAME"), ff.literal("Illinois"));
- query = new DefaultQuery(s.getSchema().getTypeName(), cf,
+ query = new Query(s.getSchema().getTypeName(), cf,
new String[] { "the_geom" });
reader = s.getFeatureReader(query, Transaction.AUTO_COMMIT);
assertEquals(1, reader.getFeatureType().getAttributeCount());
@@ -1437,12 +1441,12 @@ public void testCountTransaction() throws Exception {
String typeName = store.getSchema().getTypeName();
Id id = ff.id(Collections.singleton(ff.featureId(fid)));
- assertEquals(-1, store.getCount(new DefaultQuery(typeName, id)));
+ assertEquals(-1, store.getCount(new Query(typeName, id)));
assertEquals(1, count(ds, typeName, id, t));
store.removeFeatures(id);
- assertEquals(-1, store.getCount(new DefaultQuery(store.getSchema().getTypeName(), id)));
+ assertEquals(-1, store.getCount(new Query(store.getSchema().getTypeName(), id)));
assertEquals(initialCount - 1, count(ds, typeName, Filter.INCLUDE, t));
assertEquals(0, count(ds, typeName, id, t));
ds.dispose();
@@ -1454,7 +1458,7 @@ private int count(DataStore ds, String typeName, Filter filter) throws Exception
private int count(DataStore ds, String typeName, Filter filter, Transaction t) throws Exception {
FeatureReader<SimpleFeatureType, SimpleFeature> reader;
- reader = ds.getFeatureReader(new DefaultQuery(typeName, filter), t);
+ reader = ds.getFeatureReader(new Query(typeName, filter), t);
int count = 0;
try {
while (reader.hasNext()) {
View
12 ...plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileNullHandlingTest.java
@@ -1,11 +1,12 @@
package org.geotools.data.shapefile;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
-import java.io.IOException;
import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureStore;
-import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
@@ -30,13 +31,8 @@
SimpleFeatureCollection collection;
private SimpleFeature[] features;
- public ShapefileNullHandlingTest(String name) throws IOException {
- super(name);
- }
-
-
@Before
- protected void setUp() throws Exception {
+ public void setUp() throws Exception {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.add("geom", Point.class, 4326);
tb.add("name", String.class);
View
21 ...n/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileQuadTreeReadWriteTest.java
@@ -16,6 +16,8 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -28,19 +30,15 @@
import org.geotools.TestData;
import org.geotools.data.DataStore;
-import org.geotools.data.DefaultQuery;
import org.geotools.data.Query;
-import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.shapefile.ShapefileDataStoreFactory;
-import org.geotools.data.shapefile.index.CloseableIterator;
-import org.geotools.data.shapefile.index.Data;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.FilterFactory2;
@@ -65,13 +63,7 @@
Exception exception = null;
- /**
- * Creates a new instance of ShapefileReadWriteTest
- */
- public ShapefileQuadTreeReadWriteTest(String name) throws IOException {
- super(name);
- }
-
+ @Test
public void testAll() throws Throwable {
for (int i = 0, ii = files.length; i < ii; i++) {
test(files[i]);
@@ -85,6 +77,7 @@ public void fail(String message, Throwable cause) throws Throwable {
throw fail;
}
+ @Test
public void testReadOutside() throws Exception {
File f = copyShapefiles("shapes/statepop.shp");
ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
@@ -96,6 +89,7 @@ public void testReadOutside() throws Exception {
ds.dispose();
}
+ @Test
public void testWriteTwice() throws Exception {
copyShapefiles("shapes/stream.shp");
ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
@@ -225,6 +219,7 @@ static void compare(SimpleFeature f1, SimpleFeature f2) throws Exception {
*
* @throws Exception
*/
+ @Test
public void testGetBoundsQuery() throws Exception {
File file = copyShapefiles("shapes/streams.shp");
@@ -253,7 +248,7 @@ public void testGetBoundsQuery() throws Exception {
FeatureId id = featureId;
filter = ff.id(Collections.singleton(id));
- Query query = new DefaultQuery(ds.getTypeNames()[0], filter);
+ Query query = new Query(ds.getTypeNames()[0], filter);
Envelope result = ds.getFeatureSource().getBounds(query);
View
17 ...es/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileReadWriteTest.java
@@ -16,6 +16,8 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -29,12 +31,11 @@
import junit.framework.AssertionFailedError;
import org.geotools.TestData;
-import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -58,35 +59,37 @@
Exception exception = null;
- /** Creates a new instance of ShapefileReadWriteTest */
- public ShapefileReadWriteTest(String name) throws IOException {
- super(name);
- }
-
+ @Test
public void testReadWriteStatePop() throws Exception {
test("shapes/statepop.shp");
}
+ @Test
public void testReadWritePolygonTest() throws Exception {
test("shapes/polygontest.shp");
}
+ @Test
public void testReadWritePointTest() throws Exception {
test("shapes/pointtest.shp");
}
+ @Test
public void testReadWriteHoleTouchEdge() throws Exception {
test("shapes/holeTouchEdge.shp");
}
+ @Test
public void testReadWriteChinese() throws Exception {
test("shapes/chinese_poly.shp", Charset.forName("GB18030"));
}
+ @Test
public void testReadWriteDanishPoint() throws Exception {
test("shapes/danish_point.shp");
}
+ @Test
public void testConcurrentReadWrite() throws Exception {
System.gc();
System.runFinalization(); // If some streams are still open, it may
View
30 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShapefileTest.java
@@ -16,6 +16,10 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
@@ -30,16 +34,15 @@
import org.geotools.data.FeatureWriter;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
-import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.shp.IndexFile;
import org.geotools.data.shapefile.shp.ShapefileReader;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureStore;
-import org.geotools.feature.FeatureCollections;
+import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
@@ -66,25 +69,25 @@
public final String HOLETOUCHEDGE = "shapes/holeTouchEdge.shp";
public final String EXTRAATEND = "shapes/extraAtEnd.shp";
- public ShapefileTest(String testName) throws IOException {
- super(testName);
- }
-
+ @Test
public void testLoadingStatePop() throws Exception {
loadShapes(STATEPOP, 49);
loadMemoryMapped(STATEPOP, 49);
}
+ @Test
public void testLoadingSamplePointFile() throws Exception {
loadShapes(POINTTEST, 10);
loadMemoryMapped(POINTTEST, 10);
}
+ @Test
public void testLoadingSamplePolygonFile() throws Exception {
loadShapes(POLYGONTEST, 2);
loadMemoryMapped(POLYGONTEST, 2);
}
+ @Test
public void testLoadingTwice() throws Exception {
loadShapes(POINTTEST, 10);
loadShapes(POINTTEST, 10);
@@ -98,6 +101,7 @@ public void testLoadingTwice() throws Exception {
* It is posible for a point in a hole to touch the edge of its containing
* shell This test checks that such polygons can be loaded ok.
*/
+ @Test
public void testPolygonHoleTouchAtEdge() throws Exception {
loadShapes(HOLETOUCHEDGE, 1);
loadMemoryMapped(HOLETOUCHEDGE, 1);
@@ -108,11 +112,13 @@ public void testPolygonHoleTouchAtEdge() throws Exception {
* the normal feature area, this tests checks that this situation is delt
* with ok.
*/
+ @Test
public void testExtraAtEnd() throws Exception {
loadShapes(EXTRAATEND, 3);
loadMemoryMapped(EXTRAATEND, 3);
}
+ @Test
public void testIndexFile() throws Exception {
copyShapefiles(STATEPOP);
copyShapefiles(STATEPOP_IDX);
@@ -145,10 +151,11 @@ public void testIndexFile() throws Exception {
}
}
+ @Test
public void testHolyPolygons() throws Exception {
SimpleFeatureType type = DataUtilities.createType("junk",
"a:MultiPolygon");
- SimpleFeatureCollection features = FeatureCollections.newCollection();
+ SimpleFeatureCollection features = new DefaultFeatureCollection();
File tmpFile = getTempFile();
tmpFile.delete();
@@ -172,6 +179,7 @@ public void testHolyPolygons() throws Exception {
s.dispose();
}
+ @Test
public void testSkippingRecords() throws Exception {
final URL url = TestData.url(STATEPOP);
final ShapefileReader r = new ShapefileReader(new ShpFiles(url), false,
@@ -188,6 +196,7 @@ public void testSkippingRecords() throws Exception {
}
}
+ @Test
public void testDuplicateColumnNames() throws Exception {
File file = TestData.file(TestCaseSupport.class, "bad/state.shp");
ShapefileDataStore dataStore = new ShapefileDataStore(file.toURI().toURL());
@@ -198,6 +207,7 @@ public void testDuplicateColumnNames() throws Exception {
dataStore.dispose();
}
+ @Test
public void testShapefileReaderRecord() throws Exception {
final URL c1 = TestData.url(STATEPOP);
ShapefileReader reader = new ShapefileReader(new ShpFiles(c1), false,
@@ -225,7 +235,8 @@ public void testShapefileReaderRecord() throws Exception {
}
}
- public void testNullGeometries() throws Exception {
+ @Test
+ public void testNullGeometries() throws Exception {
// Write a point shapefile with one null geometry
Map<String, Serializable> params = new HashMap<String, Serializable>();
File tmp = File.createTempFile("test", ".dbf");
@@ -277,6 +288,7 @@ protected void loadShapes(String resource, int expected) throws Exception {
expected, cnt);
}
+ @Test
public void testReadingSparse() throws IOException {
File file = TestData.file(TestCaseSupport.class, "sparse/sparse.shp");
ShapefileReader reader = new ShapefileReader(new ShpFiles(file), false, false, new GeometryFactory());
View
14 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFileTypesTest.java
@@ -16,21 +16,23 @@
*/
package org.geotools.data.shapefile;
+import static org.junit.Assert.*;
+
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
-import junit.framework.TestCase;
-
import org.geotools.data.shapefile.files.ShpFileType;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
-public class ShpFileTypesTest extends TestCase {
+public class ShpFileTypesTest {
+ @Test
public void testToFileBase() {
ShpFileType[] values = ShpFileType.values();
@@ -40,6 +42,7 @@ public void testToFileBase() {
}
+ @Test
public void testToURLBase() throws MalformedURLException {
ShpFileType[] values = ShpFileType.values();
@@ -76,26 +79,31 @@ private void assertToFileBase(ShpFileType type) {
}
}
+ @Test
public void testNoExtension() throws Exception {
File noExtension = new File("name.");
assertNull(ShpFileType.DBF.toBase(noExtension));
}
+ @Test
public void testNoBaseName() throws Exception {
File noBase = new File(".dbf");
assertNull(ShpFileType.DBF.toBase(noBase));
}
+ @Test
public void testNoBaseNameMixedCase() throws Exception {
File noBase = new File(".dbF");
assertNull(ShpFileType.DBF.toBase(noBase));
}
+ @Test
public void testUppercase() throws Exception {
File file = new File("BLOOB.DBF");
assertEquals("BLOOB", ShpFileType.DBF.toBase(file));
}
+ @Test
public void testMixedcase() throws Exception {
File file = new File("Beebop.dBf");
assertEquals("Beebop", ShpFileType.DBF.toBase(file));
View
28 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesLockingTest.java
@@ -16,39 +16,41 @@
*/
package org.geotools.data.shapefile;
-import static org.geotools.data.shapefile.files.ShpFileType.*;
+import static org.geotools.data.shapefile.files.ShpFileType.DBF;
+import static org.geotools.data.shapefile.files.ShpFileType.SHP;
+import static org.geotools.data.shapefile.files.ShpFileType.SHX;
+import static org.junit.Assert.*;
import java.io.File;
import java.net.URL;
-import junit.framework.TestCase;
-
import org.geotools.data.shapefile.files.FileWriter;
import org.geotools.data.shapefile.files.Result;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.files.ShpFiles.State;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
-public class ShpFilesLockingTest extends TestCase implements FileWriter {
+public class ShpFilesLockingTest implements FileWriter {
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
getClass().getClassLoader().setDefaultAssertionStatus(true);
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
+ @After
+ public void tearDown() throws Exception {
Runtime.getRuntime().runFinalization();
}
+ @Test
public void testAcquireReadFile() throws Throwable {
ShpFiles shpFiles = new ShpFiles("http://somefile.com/shp.shp");
@@ -70,6 +72,7 @@ public void testAcquireReadFile() throws Throwable {
shpFiles.unlockRead(file, this);
shpFiles.dispose();
}
+ @Test
public void testAcquireWriteFile() throws Throwable {
ShpFiles shpFiles = new ShpFiles("http://somefile.com/shp.shp");
@@ -93,6 +96,7 @@ public void testAcquireWriteFile() throws Throwable {
shpFiles.dispose();
}
+ @Test
public void testAcquireRead1() throws Throwable {
ShpFiles shpFiles = new ShpFiles("http://somefile.com/shp.shp");
@@ -125,6 +129,7 @@ public String id() {
shpFiles.dispose();
}
+ @Test
public void testUnlockReadAssertion() throws Throwable {
ShpFiles shpFiles = new ShpFiles("http://somefile.com/shp.shp");
@@ -160,6 +165,7 @@ public String id() {
shpFiles.dispose();
}
+ @Test
public void testUnlockWriteAssertion() throws Throwable {
ShpFiles shpFiles = new ShpFiles("http://somefile.com/shp.shp");
View
21 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesTest.java
@@ -16,7 +16,11 @@
*/
package org.geotools.data.shapefile;
-import static org.geotools.data.shapefile.files.ShpFileType.*;
+import static org.geotools.data.shapefile.files.ShpFileType.DBF;
+import static org.geotools.data.shapefile.files.ShpFileType.PRJ;
+import static org.geotools.data.shapefile.files.ShpFileType.SHP;
+import static org.geotools.data.shapefile.files.ShpFileType.SHX;
+import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
@@ -27,19 +31,19 @@
import java.util.Map.Entry;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.geotools.data.shapefile.files.BasicShpFileWriter;
import org.geotools.data.shapefile.files.ShpFileType;
import org.geotools.data.shapefile.files.ShpFiles;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
-public class ShpFilesTest extends TestCase{
+public class ShpFilesTest {
+ @Test
public void testCaseURL() throws Exception {
assertCorrectCase(true);
assertCorrectCase(false);
@@ -78,6 +82,7 @@ private void assertCorrectCase(boolean uppercase)
}
+ @Test
public void testCaseFile() throws Exception {
Map<ShpFileType, File> files = createFiles("testCaseFile", ShpFileType.values(), true);
@@ -128,6 +133,7 @@ public void testCaseFile() throws Exception {
return files;
}
+ @Test
public void testShapefileFilesAll() throws Exception {
Map<ShpFileType, File> expected = createFiles("testShapefileFilesAll",
ShpFileType.values(), false);
@@ -138,6 +144,7 @@ public void testShapefileFilesAll() throws Exception {
assertEqualMaps(expected, shapefiles.getFileNames());
}
+ @Test
public void testURLStringConstructor() throws Exception {
Map<ShpFileType, File> expected = createFiles(
"testURLStringConstructor", ShpFileType.values(), false);
@@ -149,6 +156,7 @@ public void testURLStringConstructor() throws Exception {
assertEqualMaps(expected, shapefiles.getFileNames());
}
+ @Test
public void testFileStringConstructor() throws Exception {
Map<ShpFileType, File> expected = createFiles(
"testFileStringConstructor", ShpFileType.values(), false);
@@ -159,6 +167,7 @@ public void testFileStringConstructor() throws Exception {
assertEqualMaps(expected, shapefiles.getFileNames());
}
+ @Test
public void testShapefileFilesSome() throws Exception {
Map<ShpFileType, File> expected = createFiles("testShapefileFilesSome",
new ShpFileType[] { SHP, DBF, SHX, PRJ }, false);
@@ -170,6 +179,7 @@ public void testShapefileFilesSome() throws Exception {
assertEqualMaps(expected, shapefiles.getFileNames());
}
+ @Test
public void testBadFormat() throws Exception {
try {
new ShpFiles("SomeName.woo");
@@ -179,6 +189,7 @@ public void testBadFormat() throws Exception {
}
}
+ @Test
public void testFileInNonExistingDirectory() throws Exception {
try {
new ShpFiles(new File("nowhere/test.shp"));
@@ -188,6 +199,7 @@ public void testFileInNonExistingDirectory() throws Exception {
}
}
+ @Test
public void testNonFileURLs() throws IOException {
Map<ShpFileType, URL> expected = new HashMap<ShpFileType, URL>();
String base = "http://www.geotools.org/testFile";
@@ -207,6 +219,7 @@ public void testNonFileURLs() throws IOException {
}
}
+ @Test
public void testFileURLs() throws Exception {
Map<ShpFileType, File> expected = createFiles("testShapefileFilesAll",
ShpFileType.values(), false);
View
30 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/ShpFilesTestStream.java
@@ -16,7 +16,9 @@
*/
package org.geotools.data.shapefile;
-import static org.geotools.data.shapefile.files.ShpFileType.*;
+import static org.geotools.data.shapefile.files.ShpFileType.PRJ;
+import static org.geotools.data.shapefile.files.ShpFileType.SHP;
+import static org.junit.Assert.*;
import java.io.File;
import java.io.FileWriter;
@@ -30,30 +32,30 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
-
-import junit.framework.TestCase;
+import java.util.Set;
import org.geotools.TestData;
import org.geotools.data.shapefile.files.ShpFileType;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.files.StorageFile;
+import org.junit.Before;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
-public class ShpFilesTestStream extends TestCase implements
+public class ShpFilesTestStream implements
org.geotools.data.shapefile.files.FileWriter {
private String typeName;
private Map<ShpFileType, File> map;
private ShpFiles files;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
map = ShpFilesTest.createFiles("shpFiles", ShpFileType.values(), false);
typeName = map.get(SHP).getName();
@@ -74,15 +76,18 @@ private void writeDataToFiles() throws IOException {
}
}
+ @Test
public void testIsLocalURL() throws IOException {
ShpFiles files = new ShpFiles("http://someurl.com/file.shp");
assertFalse(files.isLocal());
}
+ @Test
public void testIsLocalFiles() throws IOException {
assertTrue(files.isLocal());
}
+ @Test
public void testDelete() throws IOException {
assertTrue(files.delete());
@@ -92,6 +97,7 @@ public void testDelete() throws IOException {
}
}
+ @Test
public void testExceptionGetInputStream() throws Exception {
ShpFiles shpFiles = new ShpFiles(new URL("http://blah/blah.shp"));
try{
@@ -102,6 +108,7 @@ public void testExceptionGetInputStream() throws Exception {
}
}
+ @Test
public void testExceptionGetOutputStream() throws Exception {
ShpFiles shpFiles = new ShpFiles(new URL("http://blah/blah.shp"));
try{
@@ -112,6 +119,7 @@ public void testExceptionGetOutputStream() throws Exception {
}
}
+ @Test
public void testExceptionGetWriteChannel() throws Exception {
ShpFiles shpFiles = new ShpFiles(new URL("http://blah/blah.shp"));
try{
@@ -122,6 +130,7 @@ public void testExceptionGetWriteChannel() throws Exception {
}
}
+ @Test
public void testExceptionGetReadChannel() throws Exception {
ShpFiles shpFiles = new ShpFiles(new URL("http://blah/blah.shp"));
try{
@@ -132,6 +141,7 @@ public void testExceptionGetReadChannel() throws Exception {
}
}
+ @Test
public void testGetInputStream() throws IOException {
writeDataToFiles();
@@ -156,6 +166,7 @@ public void testGetInputStream() throws IOException {
}
}
+ @Test
public void testGetWriteStream() throws IOException {
ShpFileType[] types = ShpFileType.values();
@@ -172,6 +183,7 @@ public void testGetWriteStream() throws IOException {
}
}
+ @Test
public void testGetReadChannelFileChannel() throws IOException {
writeDataToFiles();
@@ -181,6 +193,7 @@ public void testGetReadChannelFileChannel() throws IOException {
}
}
+ @Test
public void testGetReadChannelURL() throws IOException {
URL url = TestData.url("shapes/statepop.shp");
ShpFiles files = new ShpFiles(url);
@@ -238,6 +251,7 @@ private void doWrite(ShpFileType shpFileType) throws IOException {
assertEquals(0, files.numberOfLocks());
}
+ @Test
public void testGetWriteChannel() throws IOException {
ShpFileType[] types = ShpFileType.values();
@@ -247,12 +261,14 @@ public void testGetWriteChannel() throws IOException {
}
}
+ @Test
public void testGetStorageFile() throws Exception {
StorageFile prj = files.getStorageFile(PRJ);
assertTrue(prj.getFile().getName().startsWith(typeName));
assertTrue(prj.getFile().getName().endsWith(".prj"));
}
+ @Test
public void testGetTypeName() throws Exception {
assertEquals(typeName, files.getTypeName());
}
View
20 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/StorageFileTest.java
@@ -16,7 +16,10 @@
*/
package org.geotools.data.shapefile;
-import static org.geotools.data.shapefile.files.ShpFileType.*;
+import static org.geotools.data.shapefile.files.ShpFileType.PRJ;
+import static org.geotools.data.shapefile.files.ShpFileType.SHP;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.io.FileWriter;
@@ -26,26 +29,25 @@
import java.util.Arrays;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.geotools.data.shapefile.files.FileReader;
import org.geotools.data.shapefile.files.ShpFileType;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.files.StorageFile;
+import org.junit.Before;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
-public class StorageFileTest extends TestCase implements FileReader {
+public class StorageFileTest implements FileReader {
private ShpFiles shpFiles1;
private ShpFiles shpFiles2;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
Map<ShpFileType, File> files1 = ShpFilesTest.createFiles("Files1",
ShpFileType.values(), false);
Map<ShpFileType, File> files2 = ShpFilesTest.createFiles("Files2",
@@ -55,6 +57,7 @@ protected void setUp() throws Exception {
shpFiles2 = new ShpFiles(files2.get(SHP));
}
+ @Test
public void testReplaceOriginal() throws Exception {
ShpFiles files1 = shpFiles1;
ShpFileType type = PRJ;
@@ -102,6 +105,7 @@ private void assertCorrectData(ShpFiles files1, ShpFileType type,
}
}
+ @Test
public void testReplaceOriginals() throws Exception {
StorageFile storagePRJ1 = shpFiles1.getStorageFile(PRJ);
@@ -138,12 +142,14 @@ public void testReplaceOriginals() throws Exception {
}
}
+ @Test
public void testReplaceOriginalsEmptyArgs() throws Exception {
StorageFile.replaceOriginals(new StorageFile[0]);
}
+ @Test
public void testCompareTo() throws IOException {
StorageFile storagePRJ1 = shpFiles1.getStorageFile(PRJ);
StorageFile storageSHP1 = shpFiles1.getStorageFile(SHP);
View
17 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/TestCaseSupport.java
@@ -16,6 +16,8 @@
*/
package org.geotools.data.shapefile;
+import static junit.framework.Assert.*;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -25,14 +27,14 @@
import java.util.List;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.geotools.TestData;
import org.geotools.data.shapefile.index.CloseableIterator;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.factory.CommonFactoryFinder;
+import org.junit.After;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.filter.FilterFactory2;
@@ -55,7 +57,7 @@
* @author Ian Schneider
* @author Martin Desruisseaux
*/
-public class TestCaseSupport extends TestCase {
+public class TestCaseSupport {
/** References a known test file provided by sample data. */
@@ -87,17 +89,11 @@
private final List<File> tmpFiles = new ArrayList<File>();
/**
- * Creates a new instance of {@code TestCaseSupport} with the given name.
- */
- protected TestCaseSupport(final String name) throws IOException {
- super(name);
- }
-
- /**
* Deletes all temporary files created by {@link #getTempFile}. This method
* is automatically run after each test.
*/
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
Runtime.getRuntime().runFinalization();
// it seems that not all files marked as temp will get erased, perhaps
@@ -121,7 +117,6 @@ protected void tearDown() throws Exception {
f.remove();
}
- super.tearDown();
}
private void dieDieDIE(File file) {
View
23 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FIDTestCase.java
@@ -17,20 +17,17 @@
package org.geotools.data.shapefile.fid;
import java.io.File;
-import java.io.IOException;
import org.geotools.data.shapefile.TestCaseSupport;
import org.geotools.data.shapefile.files.ShpFiles;
+import org.junit.Before;
/**
*
*
* @source $URL$
*/
public abstract class FIDTestCase extends TestCaseSupport {
- protected FIDTestCase( String name ) throws IOException {
- super(name);
- }
protected final String TYPE_NAME = "archsites";
@@ -44,9 +41,8 @@ protected FIDTestCase( String name ) throws IOException {
protected ShpFiles shpFiles;
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUpArchsites() throws Exception {
backshp = copyShapefiles("shapes/" + TYPE_NAME + ".shp");
backdbf = sibling(backshp, "dbf");
@@ -58,18 +54,5 @@ protected void setUp() throws Exception {
shpFiles = new ShpFiles(backshx);
}
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- private void cleanup(File file) {
- if(file.exists()) {
- assertTrue(file.delete());
- }
- }
-
-
}
View
13 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FidIndexerTest.java
@@ -16,33 +16,26 @@
*/
package org.geotools.data.shapefile.fid;
-import java.io.IOException;
+import static junit.framework.Assert.assertEquals;
import org.geotools.data.DataUtilities;
import org.geotools.data.Query;
import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.shapefile.fid.FidIndexer;
-import org.geotools.data.shapefile.fid.IndexedFidReader;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.simple.SimpleFeatureSource;
+import org.junit.Test;
/**
*
*
* @source $URL$
*/
public class FidIndexerTest extends FIDTestCase {
- public FidIndexerTest( ) throws IOException {
- super("FidIndexerTest");
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
/*
* Test method for 'org.geotools.index.fid.FidIndexer.generate(URL)'
*/
+ @Test
public void testGenerate() throws Exception {
ShpFiles shpFiles = new ShpFiles(backshp.toURI().toURL());
FidIndexer.generate(shpFiles);
View
25 modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/FidQueryTest.java
@@ -16,6 +16,8 @@
*/
package org.geotools.data.shapefile.fid;
+import static junit.framework.Assert.*;
+
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
@@ -26,13 +28,14 @@
import org.geotools.data.Query;
import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.feature.DefaultFeatureCollection;
-import org.geotools.feature.FeatureCollections;
import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
@@ -49,9 +52,6 @@
* @source $URL$
*/
public class FidQueryTest extends FIDTestCase {
- public FidQueryTest() throws IOException {
- super("FidQueryTest");
- }
private ShapefileDataStore ds;
@@ -63,10 +63,8 @@ public FidQueryTest() throws IOException {
private int numFeatures;
- protected void setUp() throws Exception {
-
- super.setUp();
-
+ @Before
+ public void setUpFixQueryTest() throws Exception {
URL url = backshp.toURI().toURL();
ds = new ShapefileDataStore(url);
numFeatures = 0;
@@ -88,16 +86,17 @@ protected void setUp() throws Exception {
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void dispose() throws Exception {
ds.dispose();
- super.tearDown();
}
+ @Test
public void testGetByFID() throws Exception {
assertFidsMatch();
}
+ @Test
public void testAddFeature() throws Exception {
SimpleFeature feature = fids.values().iterator().next();
SimpleFeatureType schema = ds.getSchema();
@@ -137,6 +136,7 @@ public void testAddFeature() throws Exception {
}
}
+ @Test
public void testModifyFeature() throws Exception {
SimpleFeature feature = this.fids.values().iterator().next();
int newId = 237594123;
@@ -161,6 +161,7 @@ public void testModifyFeature() throws Exception {
this.assertFidsMatch();
}
+ @Test
public void testDeleteFeature() throws Exception {
SimpleFeatureIterator features = featureStore.getFeatures().features();
SimpleFeature feature;
View
28 .../plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/IndexedFidReaderTest.java
@@ -16,20 +16,25 @@
*/
package org.geotools.data.shapefile.fid;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;
import org.geotools.data.shapefile.ShapefileDataStore;
-import org.geotools.data.shapefile.fid.FidIndexer;
-import org.geotools.data.shapefile.fid.IndexedFidReader;
-import org.geotools.data.shapefile.fid.IndexedFidWriter;
import org.geotools.data.shapefile.files.ShpFiles;
import org.geotools.data.shapefile.shp.IndexFile;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.opengis.feature.simple.SimpleFeature;
/**
@@ -38,27 +43,24 @@
* @source $URL$
*/
public class IndexedFidReaderTest extends FIDTestCase {
- public IndexedFidReaderTest() throws IOException {
- super("IndexedFidReaderTest");
- }
private IndexedFidReader reader;
private IndexFile indexFile;
private ShpFiles shpFiles;
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUpIndexedFidReaderTest() throws Exception {
shpFiles = new ShpFiles(backshp.toURI().toURL());
FidIndexer.generate(shpFiles);
indexFile = new IndexFile(shpFiles, false);
reader = new IndexedFidReader(shpFiles);
}
- protected void tearDown() throws Exception {
+ @After
+ public void closeFiles() throws Exception {
reader.close();
indexFile.close();
shpFiles.dispose();
@@ -69,6 +71,7 @@ protected void tearDown() throws Exception {
/*
* Test method for 'org.geotools.index.fid.IndexedFidReader.findFid(String)'
*/
+ @Test
public void testFindFid() throws Exception {
long offset = reader.findFid(TYPE_NAME + ".4");
assertEquals(3, offset);
@@ -92,6 +95,7 @@ public void testFindFid() throws Exception {
assertEquals(-1, offset);
}
+ @Test
public void testFindAllFids() throws Exception {
int expectedCount = 0;
Set<String> expectedFids = new LinkedHashSet<String>();
@@ -117,6 +121,7 @@ public void testFindAllFids() throws Exception {
}
}
+ @Test
public void testFindAllFidsReverseOrder() throws Exception {
int expectedCount = 0;
Set<String> expectedFids = new TreeSet<String>(Collections.reverseOrder());
@@ -148,6 +153,7 @@ public void testFindAllFidsReverseOrder() throws Exception {
}
// test if FID no longer exists.
+ @Test
public void testFindDeletedFID() throws Exception {
reader.close();
@@ -179,6 +185,7 @@ public void testFindDeletedFID() throws Exception {
}
+ @Test
public void testHardToFindFid() throws Exception {
long offset = reader.search(5, 3, 7, 5);
assertEquals(4, offset);
@@ -187,6 +194,7 @@ public void testHardToFindFid() throws Exception {
/*
* Test method for 'org.geotools.index.fid.IndexedFidReader.goTo(int)'
*/
+ @Test
public void testGoTo() throws IOException {
reader.goTo(10);
assertEquals(shpFiles.getTypeName() + ".11", reader.next());
View
31 .../plugin/shapefile/src/test/java/org/geotools/data/shapefile/fid/IndexedFidWriterTest.java
@@ -16,13 +16,15 @@
*/
package org.geotools.data.shapefile.fid;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
import java.io.IOException;
import java.net.MalformedURLException;
-import org.geotools.data.shapefile.fid.FidIndexer;
-import org.geotools.data.shapefile.fid.IndexedFidReader;
-import org.geotools.data.shapefile.fid.IndexedFidWriter;
import org.geotools.data.shapefile.shp.IndexFile;
+import org.junit.After;
+import org.junit.Test;
/**
*
@@ -33,26 +35,15 @@
private IndexFile indexFile;
private IndexedFidWriter writer;
- public IndexedFidWriterTest() throws IOException {
- super("IndexedFidWriterTest");
- }
- protected void setUp() throws Exception {
- super.setUp();
- }
-
private void initWriter() throws IOException, MalformedURLException {
close();
indexFile = new IndexFile(shpFiles, false);
writer = new IndexedFidWriter(shpFiles);
}
- protected void tearDown() throws Exception {
- close();
- super.tearDown();
- }
-
- private void close() throws IOException {
+ @After
+ public void close() throws IOException {
if ((writer != null) && !writer.isClosed()) {
writer.close();
}
@@ -69,6 +60,7 @@ private void close() throws IOException {
/*
* Test method for 'org.geotools.index.fid.IndexedFidWriter.hasNext()'
*/
+ @Test
public void testHasNext() throws MalformedURLException, IOException {
FidIndexer.generate(backshp.toURI().toURL());
initWriter();
@@ -82,6 +74,7 @@ public void testHasNext() throws MalformedURLException, IOException {
/*
* Test method for 'org.geotools.index.fid.IndexedFidWriter.remove()'
*/
+ @Test
public void testRemove() throws MalformedURLException, IOException {
FidIndexer.generate(backshp.toURI().toURL());
initWriter();
@@ -104,6 +97,7 @@ public void testRemove() throws MalformedURLException, IOException {
}
}
+ @Test
public void testRemoveCounting() throws Exception {
FidIndexer.generate(backshp.toURI().toURL());
initWriter();
@@ -158,6 +152,7 @@ public void testRemoveCounting() throws Exception {
/*
* Test method for 'org.geotools.index.fid.IndexedFidWriter.write()'
*/
+ @Test
public void testWrite() throws IOException {
initWriter();
@@ -166,10 +161,8 @@ public void testWrite() throws IOException {
writer.write();
}
- close();
initWriter();
-
- for( int i = 1; i < 5; i++ ) {
+ for( int i = 1; i <= 5; i++ ) {
assertTrue(writer.hasNext());
assertEquals((long) i, writer.next());
}
View
15 ...s/plugin/shapefile/src/test/java/org/geotools/data/shapefile/shp/PolygonHandler2Test.java
@@ -16,12 +16,12 @@
*/
package org.geotools.data.shapefile.shp;
+import static org.junit.Assert.*;
+
import java.awt.Dimension;
-import java.io.IOException;
import java.util.ArrayList;
-import org.geotools.data.shapefile.shp.PolygonHandler;
-import org.geotools.data.shapefile.shp.ShapeType;
+import org.junit.Test;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
@@ -37,14 +37,8 @@
* @author Ian Schneider
*/
public class PolygonHandler2Test extends org.geotools.data.shapefile.TestCaseSupport {
- public PolygonHandler2Test(String testName) throws IOException {
- super(testName);
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(suite(PolygonHandlerTest.class));
- }
+ @Test
public void testPolygonHandler() {
Coordinate[] c = new Coordinate[3];
c[0] = new Coordinate(0, 0, 0);
@@ -59,6 +53,7 @@ public void testPolygonHandler() {
}
}
+ @Test
public void testHoleAssignment() {
Dimension ps = new Dimension(500, 500);
PrecisionModel precision = new PrecisionModel();
View
16 ...es/plugin/shapefile/src/test/java/org/geotools/data/shapefile/shp/PolygonHandlerTest.java
@@ -16,12 +16,12 @@
*/
package org.geotools.data.shapefile.shp;
-import java.io.IOException;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import org.geotools.data.shapefile.TestCaseSupport;
-import org.geotools.data.shapefile.shp.PolygonHandler;
-import org.geotools.data.shapefile.shp.ShapeType;
+import org.junit.Test;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
@@ -39,14 +39,7 @@
*/
public class PolygonHandlerTest extends TestCaseSupport {
- public PolygonHandlerTest(String testName) throws IOException {
- super(testName);
- }
-
- public static void main(java.lang.String[] args) {
- junit.textui.TestRunner.run(suite(PolygonHandlerTest.class));
- }
-
+ @Test
public void testPolygonHandler() {
Coordinate[] c = new Coordinate[3];
c[0] = new Coordinate(0, 0, 0);
@@ -59,6 +52,7 @@ public void testPolygonHandler() {
}
}
+ @Test
public void testHoleAssignment() {
java.awt.Dimension ps = new java.awt.Dimension(500, 500);
PrecisionModel precision = new PrecisionModel();
View
16 ...gin/shapefile/src/test/java/org/geotools/data/shapefile/shp/xml/ShpXmlFileReaderTest.java
@@ -16,16 +16,15 @@
*/
package org.geotools.data.shapefile.shp.xml;
-import java.net.URL;
+import static org.junit.Assert.*;
-import junit.framework.TestCase;
+import java.net.URL;
import org.geotools.TestData;
import org.geotools.data.shapefile.TestCaseSupport;
import org.geotools.data.shapefile.files.ShpFiles;
-import org.geotools.data.shapefile.shp.xml.IdInfo;
-import org.geotools.data.shapefile.shp.xml.Metadata;
-import org.geotools.data.shapefile.shp.xml.ShpXmlFileReader;
+import org.junit.Before;
+import org.junit.Test;
import com.vividsolutions.jts.geom.Envelope;
@@ -34,17 +33,18 @@
*
* @source $URL$
*/
-public class ShpXmlFileReaderTest extends TestCase {
+public class ShpXmlFileReaderTest {
ShpXmlFileReader reader;
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
URL example = TestData.url(TestCaseSupport.class, "example.shp.xml");
ShpFiles shpFiles = new ShpFiles(example);
reader = new ShpXmlFileReader(shpFiles);
}
+ @Test
public void testBBox() {
Metadata meta = reader.parse();
assertNotNull("meta", meta);

0 comments on commit c951a61

Please sign in to comment.
Something went wrong with that request. Please try again.