1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.beep4j.internal.message.contenttype;
17
18 import java.io.StringReader;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import junit.framework.TestCase;
24
25 public class ContentTypeParserTest extends TestCase {
26
27 public void testContentType() throws Exception {
28 test("one/two", "one", "two", new HashMap<String,String>());
29 }
30
31 public void testContentTypeWithParameter() throws ParseException {
32 test("one/two; three = four",
33 "one", "two",
34 Collections.singletonMap("three", "four"));
35 }
36
37 public void testContentTypeWithQuotedParameter() throws Exception {
38 test("one/(foo)two; three = \"four\"",
39 "one", "two",
40 Collections.singletonMap("three", "four"));
41 }
42
43 public void testContentTypeWithComments() throws Exception {
44 test("one(foo)/two; three = (foo) four",
45 "one", "two",
46 Collections.singletonMap("three", "four"));
47 }
48
49 private void test(String val,
50 String expectedType, String expectedSubtype,
51 Map<String,String> parameters) throws ParseException {
52
53 ContentTypeParser parser = new ContentTypeParser(new StringReader(val));
54 parser.parseAll();
55
56 String type = parser.getType();
57 String subtype = parser.getSubType();
58
59 assertEquals(parameters, parser.getParameters());
60
61 assertEquals(expectedType, type);
62 assertEquals(expectedSubtype, subtype);
63 }
64
65 }