1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.tika.mime;
18
19 import junit.framework.TestCase;
20
21 public class MimeTypeTest extends TestCase {
22
23 private MimeTypes types;
24 private MimeType text;
25
26 protected void setUp() throws MimeTypeException {
27 types = new MimeTypes();
28 text = types.forName("text/plain");
29 }
30
31
32 public void testConstrctor() {
33
34
35 try {
36 new MimeType(null, "text/plain");
37 fail("Expected IllegalArgumentException");
38 } catch (IllegalArgumentException e) {
39
40 }
41
42
43 try {
44 new MimeType(types, null);
45 fail("Expected IllegalArgumentException");
46 } catch (IllegalArgumentException e) {
47
48 }
49
50
51 try {
52 new MimeType(types, "application");
53 fail("Expected IllegalArgumentException");
54 } catch (IllegalArgumentException e) {
55
56 }
57
58
59 try {
60 new MimeType(types, "TEXT/PLAIN");
61 fail("Expected IllegalArgumentException");
62 } catch (IllegalArgumentException e) {
63
64 }
65 }
66
67 public void testIsValidName() {
68 assertTrue(MimeType.isValid("application/octet-stream"));
69 assertTrue(MimeType.isValid("text/plain"));
70 assertTrue(MimeType.isValid("foo/bar"));
71 assertTrue(MimeType.isValid("a/b"));
72
73 assertFalse(MimeType.isValid("application"));
74 assertFalse(MimeType.isValid("application/"));
75 assertFalse(MimeType.isValid("/"));
76 assertFalse(MimeType.isValid("/octet-stream"));
77 assertFalse(MimeType.isValid("application//octet-stream"));
78 assertFalse(MimeType.isValid("application/octet=stream"));
79 assertFalse(MimeType.isValid("application/\u00f6ctet-stream"));
80 assertFalse(MimeType.isValid("text/plain;"));
81 assertFalse(MimeType.isValid("text/plain; charset=UTF-8"));
82 try {
83 MimeType.isValid(null);
84 fail("Expected IllegalArgumentException");
85 } catch (IllegalArgumentException e) {
86
87 }
88 }
89
90
91 public void testSetDescription() {
92 try {
93 text.setDescription(null);
94 fail("Expected IllegalArgumentException");
95 } catch (IllegalArgumentException e) {
96
97 }
98 }
99
100
101 public void testSetSuperType() throws MimeTypeException {
102 try {
103 text.setSuperType(null);
104 fail("Expected IllegalArgumentException");
105 } catch (IllegalArgumentException e) {
106
107 }
108 }
109
110 }