aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector/gc/UTFGridPositionTest.java
blob: a742fafa49ea1062f0027548f90ab54287a7487a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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());
    }

}