aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java
blob: fe790afeed188444dd486c42f4ca05f6deec3b86 (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
package cgeo.geocaching.utils;

import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.test.mock.MockedCache;

import android.test.AndroidTestCase;

public class BaseUtilsTest extends AndroidTestCase {
    public static void testRegEx() {
        String page = MockedCache.readCachePage("GC2CJPF");
        assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
        assertTrue(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???")));
        int cachesFound = 0;
        try {
            cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""));
        } catch (NumberFormatException e) {
            fail();
        }
        assertTrue(cachesFound >= 491);
    }

    public static void testReplaceWhitespaces() {
        assertEquals("foo bar baz ", BaseUtils.replaceWhitespace("  foo\n\tbar   \r   baz  "));
    }

}