View difference between Paste ID: Jpn6B3qS and W67kdDsy
SHOW: | | - or go back to the newest paste.
1
package mapdecoder;
2
3
import org.junit.Test;
4
5
import java.util.Map;
6
7
import static org.junit.Assert.*;
8
9
public class MyMapDecoderTest {
10
11
    @Test
12
    public void testSample1() {
13
        String entry = "one=1&two=2";
14
        MyMapDecoder myMapDecoder = new MyMapDecoder();
15
        Map<String, String> result= myMapDecoder.decode(entry);
16
17
        assertEquals("1", result.get("one"));
18
        assertEquals("2", result.get("two"));
19
    }
20
21
    @Test
22
    public void testNullInput() {
23
        String entry = null;
24
        MyMapDecoder myMapDecoder = new MyMapDecoder();
25
        Map<String, String> result = myMapDecoder.decode(entry);
26
27
        assertEquals(null, result);
28
    }
29
30
    @Test
31
    public void testEmptyString() {
32
        String entry = "";
33
        MyMapDecoder myMapDecoder = new MyMapDecoder();
34
        Map<String, String> emptyMap = myMapDecoder.decode(entry);
35
        assertNotNull(emptyMap);
36
        assertEquals(0, emptyMap.size());
37
    }
38
39
    @Test(expected = IllegalArgumentException.class)
40
    public void testException1() {
41
        String entry = "one=1&&two=2";
42
        MyMapDecoder myMapDecoder = new MyMapDecoder();
43
44
        Map<String, String> result = myMapDecoder.decode(entry);
45
    }
46
47
    @Test(expected = IllegalArgumentException.class)
48
    public void testException2() {
49
        String entry = "one=1=&two=2";
50
        MyMapDecoder myMapDecoder = new MyMapDecoder();
51
52
        Map<String, String> result = myMapDecoder.decode(entry);
53
    }
54
55
}