aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/utils/CryptUtilsTest.java
blob: 7175f3da82766002b7e1741f9fcf462c8db38671 (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.utils;

import static org.assertj.core.api.Assertions.assertThat;

import cgeo.geocaching.connector.gc.GCConstants;

import junit.framework.TestCase;

public class CryptUtilsTest extends TestCase {
    public static void testROT13() {
        assertThat(CryptUtils.rot13("")).isEqualTo("");
        assertThat(CryptUtils.rot13((String) null)).isEqualTo("");
        assertThat(CryptUtils.rot13("Cache hint")).isEqualTo("Pnpur uvag");
        assertThat(CryptUtils.rot13("Cache [plain] hint")).isEqualTo("Pnpur [plain] uvag");
        assertThat(CryptUtils.rot13("[all plain]")).isEqualTo("[all plain]");
        assertThat(CryptUtils.rot13("123")).isEqualTo("123");
    }

    public static void testConvertToGcBase31() {
        assertThat(GCConstants.gccodeToGCId("GC1PKK9")).isEqualTo(1186660);
        assertThat(GCConstants.gccodeToGCId("GC1234")).isEqualTo(4660);
        assertThat(GCConstants.gccodeToGCId("GCF123")).isEqualTo(61731);
    }

    public static void testIssue1902() {
        assertThat(CryptUtils.rot13("ƖƖyƖƖƖƖ")).isEqualTo("ƖƖlƖƖƖƖ");
    }

    public static void testMd5() {
        assertThat(CryptUtils.md5("")).isEqualTo("d41d8cd98f00b204e9800998ecf8427e");
        // expected value taken from debugger. should assure every developer uses UTF-8
        assertThat(CryptUtils.md5("äöü")).isEqualTo("a7f4e3ec08f09be2ef7ecb4eea5f8981");
    }
}