From 6e66c8f2da1d6893e2d9e100957a966bc3f9e69a Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 13 Jan 2013 08:15:14 +0100 Subject: fix #2389: Parse errors in cgeocoords --- .../src/cgeo/geocaching/geopoint/GeopointTest.java | 67 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'tests/src') diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java index 93b1339..1401cb6 100644 --- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java +++ b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java @@ -1,10 +1,10 @@ package cgeo.geocaching.geopoint; -import junit.framework.Assert; - import android.os.Bundle; import android.test.AndroidTestCase; +import junit.framework.Assert; + public class GeopointTest extends AndroidTestCase { public static void testCreation() { @@ -234,4 +234,67 @@ public class GeopointTest extends AndroidTestCase { assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1); } + private static void assertParseException(Runnable runnable) { + try { + runnable.run(); + Assert.fail("Should have thrown Geopoint.ParseException"); + } catch (Geopoint.ParseException e) { + //success + } + } + + public static void testParseParam1() { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("some nonsense text"); + } + }); + } + + public static void testParseParam2() throws Exception { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latitude", "longitude"); + } + }); + } + + public static void testParseParam6() throws Exception { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latDegFrac", "lonDir", "lonDeg", "lonDegFrac"); + } + }); + } + + public static void testParseParam8() throws Exception { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latMin", "latMinFrac", "lonDir", "lonDeg", "lonMin", "lonMinFrac"); + } + }); + } + + public static void testParseParam10() throws Exception { + assertParseException(new Runnable() { + + @SuppressWarnings("unused") + @Override + public void run() { + new Geopoint("latDir", "latDeg", "latMin", "latSec", "latSecFrac", "lonDir", "lonDeg", "lonMin", "lonSec", "lonSecFrac"); + } + }); + } } -- cgit v1.1