1. Ville Saalo
  2. GeoGPXParser

Commits

Ville Saalo  committed 8dac1d9

Tests for the CacheListParser class. Separated common test data from OwnerStatsParser into the new AbstractParserTest class.

  • Participants
  • Parent commits a156a67
  • Branches default

Comments (0)

Files changed (3)

File test/geogpxparser/AbstractParserTest.java

View file
+package geogpxparser;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.joda.time.DateTime;
+
+/**
+ * Provides test data for subclasses.
+ */
+public abstract class AbstractParserTest {
+    protected List<Geocache> caches;
+
+    public AbstractParserTest() {
+        caches = new ArrayList<>();
+        Geocache cache1 = new Geocache();
+        cache1.setGcCode("GC111");
+        cache1.setName("Cache I");
+        cache1.setOwner("John");
+        cache1.setType(Geocache.CacheType.Traditional);
+        cache1.setLongitude(1.1);
+        cache1.setLatitude(2.2);
+        cache1.setSize(Geocache.CacheSize.Micro);
+        cache1.setDifficulty(1);
+        cache1.setTerrain(5);
+        cache1.setPublished(new DateTime(2001, 1, 2, 00, 00));
+        
+        Geocache cache2 = new Geocache();
+        cache2.setGcCode("GC222");
+        cache2.setName("Cache II");
+        cache2.setOwner("Mike");
+        cache2.setType(Geocache.CacheType.Multi);
+        cache2.setLongitude(3.3);
+        cache2.setLatitude(4.4);
+        cache2.setSize(Geocache.CacheSize.Small);
+        cache2.setDifficulty(1.5f);
+        cache2.setTerrain(4.5f);
+        cache2.setPublished(new DateTime(2002, 3, 4, 01, 00));
+        
+        Geocache cache3 = new Geocache();
+        cache3.setGcCode("GC333");
+        cache3.setName("Cache III");
+        cache3.setOwner("John");
+        cache3.setType(Geocache.CacheType.Traditional);
+        cache3.setLongitude(5.5);
+        cache3.setLatitude(6.6);
+        cache3.setSize(Geocache.CacheSize.Regular);
+        cache3.setDifficulty(2);
+        cache3.setTerrain(4);
+        cache3.setPublished(new DateTime(2003, 5, 6, 02, 00));
+        
+        Geocache cache4 = new Geocache();
+        cache4.setGcCode("GC444");
+        cache4.setName("Cache IV");
+        cache4.setOwner("Mike");
+        cache4.setType(Geocache.CacheType.Letterbox);
+        cache4.setLongitude(7.7);
+        cache4.setLatitude(8.8);
+        cache4.setSize(Geocache.CacheSize.Large);
+        cache4.setDifficulty(2.5f);
+        cache4.setTerrain(3.5f);
+        cache4.setPublished(new DateTime(2004, 7, 8, 03, 00));
+        
+        Geocache cache5 = new Geocache();
+        cache5.setGcCode("GC555");
+        cache5.setName("Cache V");
+        cache5.setOwner("Jake");
+        cache5.setType(Geocache.CacheType.Mystery);
+        cache5.setLongitude(9.9);
+        cache5.setLatitude(10.10);
+        cache5.setSize(Geocache.CacheSize.Not_chosen);
+        cache5.setDifficulty(3);
+        cache5.setTerrain(3);
+        cache5.setPublished(new DateTime(2005, 9, 10, 06, 07));
+        
+        caches.add(cache1);
+        caches.add(cache2);
+        caches.add(cache3);
+        caches.add(cache4);
+        caches.add(cache5);
+    }
+    
+}

File test/geogpxparser/CacheListParserTest.java

View file
+package geogpxparser;
+
+import geogpxparser.tabular.TableData;
+import geogpxparser.tabular.TableRow;
+import java.util.List;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+/**
+ * Tests the CacheListParser.
+ */
+public class CacheListParserTest extends AbstractParserTest {
+    
+    @Test
+    public void test_getTabularInfo() {
+        TableData result = new CacheListParser().getTabularInfo(caches);
+        assertNotNull(result);
+        
+        List<TableRow> rows = result.getRows();
+        assertNotNull(rows);
+        assertEquals(6, rows.size());
+        
+        int row = 0;
+        assertTrue(rows.get(0).isHeader());
+        int col = 0;
+        
+        assertEquals("gccode", rows.get(row).getCells().get(col++).getText());
+        assertEquals("type", rows.get(row).getCells().get(col++).getText());
+        assertEquals("name", rows.get(row).getCells().get(col++).getText());
+        assertEquals("longitude", rows.get(row).getCells().get(col++).getText());
+        assertEquals("latitude", rows.get(row).getCells().get(col++).getText());
+        assertEquals("size", rows.get(row).getCells().get(col++).getText());
+        assertEquals("difficulty", rows.get(row).getCells().get(col++).getText());
+        assertEquals("terrain", rows.get(row).getCells().get(col++).getText());
+        assertEquals("published", rows.get(row).getCells().get(col++).getText());
+        assertEquals("owner", rows.get(row).getCells().get(col++).getText());
+        
+        row = 1;
+        col = 0;
+        assertEquals("GC111", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Traditional", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Cache I", rows.get(row).getCells().get(col++).getText());
+        assertEquals("1.1", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2.2", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Micro", rows.get(row).getCells().get(col++).getText());
+        assertEquals("1.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("5.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2001-01-02", rows.get(row).getCells().get(col++).getText());
+        assertEquals("John", rows.get(row).getCells().get(col++).getText());
+        
+        row = 2;
+        col = 0;
+        assertEquals("GC222", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Multi", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Cache II", rows.get(row).getCells().get(col++).getText());
+        assertEquals("3.3", rows.get(row).getCells().get(col++).getText());
+        assertEquals("4.4", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Small", rows.get(row).getCells().get(col++).getText());
+        assertEquals("1.5", rows.get(row).getCells().get(col++).getText());
+        assertEquals("4.5", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2002-03-04", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Mike", rows.get(row).getCells().get(col++).getText());
+        
+        row = 3;
+        col = 0;
+        assertEquals("GC333", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Traditional", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Cache III", rows.get(row).getCells().get(col++).getText());
+        assertEquals("5.5", rows.get(row).getCells().get(col++).getText());
+        assertEquals("6.6", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Regular", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("4.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2003-05-06", rows.get(row).getCells().get(col++).getText());
+        assertEquals("John", rows.get(row).getCells().get(col++).getText());
+        
+        row = 4;
+        col = 0;
+        assertEquals("GC444", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Letterbox", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Cache IV", rows.get(row).getCells().get(col++).getText());
+        assertEquals("7.7", rows.get(row).getCells().get(col++).getText());
+        assertEquals("8.8", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Large", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2.5", rows.get(row).getCells().get(col++).getText());
+        assertEquals("3.5", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2004-07-08", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Mike", rows.get(row).getCells().get(col++).getText());
+        
+        row = 5;
+        col = 0;
+        assertEquals("GC555", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Mystery", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Cache V", rows.get(row).getCells().get(col++).getText());
+        assertEquals("9.9", rows.get(row).getCells().get(col++).getText());
+        assertEquals("10.1", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Not_chosen", rows.get(row).getCells().get(col++).getText());
+        assertEquals("3.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("3.0", rows.get(row).getCells().get(col++).getText());
+        assertEquals("2005-09-10", rows.get(row).getCells().get(col++).getText());
+        assertEquals("Jake", rows.get(row).getCells().get(col++).getText());
+    }
+}

File test/geogpxparser/OwnerStatsParserTest.java

View file
 
 import geogpxparser.tabular.TableData;
 import geogpxparser.tabular.TableRow;
-import java.util.ArrayList;
 import java.util.List;
 import static org.junit.Assert.*;
 import org.junit.Test;
 /**
  * Tests for the OwnerStatsParser class.
  */
-public class OwnerStatsParserTest {
+public class OwnerStatsParserTest extends AbstractParserTest {
     
-    private List<Geocache> caches;
-    
-    public OwnerStatsParserTest() {
-        caches = new ArrayList<>();
-        Geocache cache1 = new Geocache();
-        cache1.setOwner("John");
-        cache1.setType(Geocache.CacheType.Traditional);
-        
-        Geocache cache2 = new Geocache();
-        cache2.setOwner("Mike");
-        cache2.setType(Geocache.CacheType.Multi);
-        
-        Geocache cache3 = new Geocache();
-        cache3.setOwner("John");
-        cache3.setType(Geocache.CacheType.Traditional);
-        
-        Geocache cache4 = new Geocache();
-        cache4.setOwner("Mike");
-        cache4.setType(Geocache.CacheType.Letterbox);
-        
-        Geocache cache5 = new Geocache();
-        cache5.setOwner("Jake");
-        cache5.setType(Geocache.CacheType.Mystery);
-        
-        caches.add(cache1);
-        caches.add(cache2);
-        caches.add(cache3);
-        caches.add(cache4);
-        caches.add(cache5);
-    }
-
     @Test
     public void test_getTabularInfo() {
         // Assert that the test data has been initialized correctly: