aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/test/org/openintents/openpgp/OpenPgpUtilsTest.java
blob: f115398f293a90606eb532df237620bbda0eb3dd (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package test.org.openintents.openpgp;

import org.openintents.openpgp.util.OpenPgpUtils;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;

import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.openintents.openpgp.util.OpenPgpUtils;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;

@RunWith(AndroidJUnit4.class)
public class OpenPgpUtilsTest {
    @Test
    public void splitCompleteUserIdShouldReturnAll3Components() throws Exception {
        OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann (this is a comment) <max@example.com>");
        assertEquals("Max Mustermann", info.name);
        assertEquals("this is a comment", info.comment);
        assertEquals("max@example.com", info.email);
    }

    @Test
    public void splitUserIdWithAllButCommentShouldReturnNameAndEmail() throws Exception {
        OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann <max@example.com>");
        assertEquals("Max Mustermann", info.name);
        assertNull(info.comment);
        assertEquals("max@example.com", info.email);
    }

    @Test
    public void splitUserIdWithAllButEmailShouldReturnNameAndComment() throws Exception {
        OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann (this is a comment)");
        assertEquals(info.name, "Max Mustermann");
        assertEquals(info.comment, "this is a comment");
        assertNull(info.email);
    }

    @Test
    public void splitUserIdWithOnlyNameShouldReturnNameOnly() throws Exception {
        OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann [this is a nothing]");
        assertEquals("Max Mustermann", info.name);
        assertNull(info.comment);
        assertNull(info.email);
    }
}