diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-09-15 20:16:42 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-09-15 20:16:42 +0200 |
| commit | 46b5dd9f3a7e482e451744ff9ea71919b83f5801 (patch) | |
| tree | b9572a348745714e2744e9de5a3521a108cd5fff | |
| parent | b45726aaab73836b1c69e14ff0f053975e427bb4 (diff) | |
| download | cgeo-46b5dd9f3a7e482e451744ff9ea71919b83f5801.zip cgeo-46b5dd9f3a7e482e451744ff9ea71919b83f5801.tar.gz cgeo-46b5dd9f3a7e482e451744ff9ea71919b83f5801.tar.bz2 | |
assertion badly triggered in tests of UTFGridPosition
* convert assertion to exception, as nobody noticed this before
* move tests to where they belong
3 files changed, 40 insertions, 16 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java b/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java index 5965fff..eff193a 100644 --- a/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java +++ b/main/src/cgeo/geocaching/connector/gc/UTFGridPosition.java @@ -15,9 +15,12 @@ public final class UTFGridPosition { private final static Pattern PATTERN_JSON_KEY = Pattern.compile("[^\\d]*" + "(\\d+),\\s*(\\d+)" + "[^\\d]*"); // (12, 34) public UTFGridPosition(final int x, final int y) { - assert x >= 0 && x <= UTFGrid.GRID_MAXX : "x outside bounds"; - assert y >= 0 && y <= UTFGrid.GRID_MAXY : "y outside bounds"; - + if (x < 0 || x > UTFGrid.GRID_MAXX) { + throw new IllegalArgumentException("x outside bounds"); + } + if (y < 0 || y > UTFGrid.GRID_MAXY) { + throw new IllegalArgumentException("y outside bounds"); + } this.x = x; this.y = y; } diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java index d70ab9b..29fd886 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java @@ -14,19 +14,6 @@ import junit.framework.TestCase; public class GCBaseTest extends TestCase { - public static void testSplitJSONKey() { - assertKey("(1, 2)", 1, 2); - assertKey("(12, 34)", 12, 34); - assertKey("(1234,56)", 1234, 56); - assertKey("(1234, 567)", 1234, 567); - } - - private static void assertKey(String key, int x, int y) { - final UTFGridPosition pos = UTFGridPosition.fromString(key); - assertEquals(x, pos.getX()); - assertEquals(y, pos.getY()); - } - public static void testSearchFromMap() { final MockedCache mockedCache = new GC2CJPF(); diff --git a/tests/src/cgeo/geocaching/connector/gc/UTFGridPositionTest.java b/tests/src/cgeo/geocaching/connector/gc/UTFGridPositionTest.java new file mode 100644 index 0000000..a742faf --- /dev/null +++ b/tests/src/cgeo/geocaching/connector/gc/UTFGridPositionTest.java @@ -0,0 +1,34 @@ +package cgeo.geocaching.connector.gc; + +import junit.framework.TestCase; + +public class UTFGridPositionTest extends TestCase { + + public static void testValidUTFGridPosition() { + assertNotNull(new UTFGridPosition(0, 0)); + } + + public static void testInvalidUTFGridPosition() { + boolean valid = true; + try { + assertNotNull(new UTFGridPosition(-1, 0)); + } catch (Exception e) { + valid = false; + } + assertFalse(valid); + } + + public static void testFromString() throws Exception { + assertXYFromString("(1, 2)", 1, 2); + assertXYFromString("(12, 34)", 12, 34); + assertXYFromString("(34,56)", 34, 56); + assertXYFromString("(34, 56)", 34, 56); + } + + private static void assertXYFromString(final String key, int x, int y) { + final UTFGridPosition pos = UTFGridPosition.fromString(key); + assertEquals(x, pos.getX()); + assertEquals(y, pos.getY()); + } + +} |
