| 1 |
package ezvcard.parameter; |
| 2 |
|
| 3 |
import static org.junit.Assert.assertSame; |
| 4 |
|
| 5 |
import org.junit.Before; |
| 6 |
import org.junit.Test; |
| 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 |
public class MediaTypeCaseClassesTest { |
| 37 |
private MediaTypeCaseClasses<TextMediaType> caseClasses; |
| 38 |
|
| 39 |
@Before |
| 40 |
public void before() { |
| 41 |
caseClasses = new MediaTypeCaseClasses<>(TextMediaType.class); |
| 42 |
} |
| 43 |
|
| 44 |
@Test |
| 45 |
public void get() { |
| 46 |
assertSame(TextMediaType.XML, caseClasses.get(new String[] { "xml", null, null })); |
| 47 |
|
| 48 |
TextMediaType rtf = caseClasses.get(new String[] { "rtf", "text/rtf", "rtf" }); |
| 49 |
assertSame(rtf, caseClasses.get(new String[] { "rtf", "text/rtf", "rtf" })); |
| 50 |
assertSame(rtf, caseClasses.get(new String[] { "rtf", null, null })); |
| 51 |
assertSame(rtf, caseClasses.get(new String[] { null, "text/rtf", null })); |
| 52 |
assertSame(rtf, caseClasses.get(new String[] { null, null, "rtf" })); |
| 53 |
} |
| 54 |
|
| 55 |
@Test |
| 56 |
public void find() { |
| 57 |
|
| 58 |
caseClasses.get(new String[] { "rtf", "text/rtf", "rtf" }); |
| 59 |
|
| 60 |
assertFind("XmL", null, null, TextMediaType.XML); |
| 61 |
assertFind("rtf", null, null, null); |
| 62 |
assertFind(null, "TEXT/xml", null, TextMediaType.XML); |
| 63 |
assertFind(null, "foo/bar", null, null); |
| 64 |
assertFind(null, null, "xML", TextMediaType.XML); |
| 65 |
assertFind(null, null, "foo", null); |
| 66 |
assertFind("xml", "TEXT/xml", null, TextMediaType.XML); |
| 67 |
assertFind("xml", "foo/bar", null, null); |
| 68 |
assertFind("xml", null, "xML", TextMediaType.XML); |
| 69 |
assertFind("xml", null, "foo", null); |
| 70 |
assertFind(null, "text/xml", "xML", TextMediaType.XML); |
| 71 |
assertFind(null, "text/xml", "foo", null); |
| 72 |
assertFind("xml", "text/xml", "xML", TextMediaType.XML); |
| 73 |
assertFind("xml", "text/xml", "foo", null); |
| 74 |
} |
| 75 |
|
| 76 |
private void assertFind(String type, String mediaType, String extension, TextMediaType expected) { |
| 77 |
TextMediaType actual = caseClasses.find(new String[] { type, mediaType, extension }); |
| 78 |
assertSame("Expected = " + expected + ", Actual = " + actual, expected, actual); |
| 79 |
} |
| 80 |
|
| 81 |
public static class TextMediaType extends MediaTypeParameter { |
| 82 |
public static final TextMediaType PLAIN = new TextMediaType("plain", "text/plain", "txt"); |
| 83 |
public static final TextMediaType XML = new TextMediaType("xml", "text/xml", "xml"); |
| 84 |
public static final TextMediaType HTML = new TextMediaType("html", "text/html", "html"); |
| 85 |
|
| 86 |
private TextMediaType(String value, String mediaType, String extension) { |
| 87 |
super(value, mediaType, extension); |
| 88 |
} |
| 89 |
} |
| 90 |
} |