1 19 20 package org.netbeans.api.editor.mimelookup; 21 22 import org.netbeans.junit.NbTestCase; 23 24 25 30 public class MimePathTest extends NbTestCase { 31 32 public MimePathTest(java.lang.String testName) { 33 super(testName); 34 } 35 36 public void testParsing(){ 37 String path = "text/x-java/text/x-ant+xml/text/html/text/xml"; 38 MimePath mp = MimePath.parse(path); 39 String parsedPath = mp.getPath(); 40 assertTrue(path.equals(parsedPath)); 41 42 int size = mp.size(); 43 assertTrue(size == 4); 44 45 String one = mp.getMimeType(0); 46 String two = mp.getMimeType(1); 47 String three = mp.getMimeType(2); 48 String four = mp.getMimeType(3); 49 50 assertTrue("text/x-java".equals(one)); 51 assertTrue("text/x-ant+xml".equals(two)); 52 assertTrue("text/html".equals(three)); 53 assertTrue("text/xml".equals(four)); 54 55 MimePath mpPrefix = mp.getPrefix(2); 56 assertTrue("text/x-java/text/x-ant+xml".equals(mpPrefix.getPath())); 57 } 58 59 public void testMimeTypeCorrectnessCheck() { 60 String [] valid = new String [] { 61 "text/plain", 62 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$&.+-^_/abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!#$&.+-^_" 63 }; 64 String [] invalid = new String [] { 65 "/", 66 "text", 67 "text//aaa", 68 "text@aaa", 69 "text/aaa/bb", 70 "text/ aaa", 71 }; 72 73 { 77 MimePath mimePath = MimePath.get(""); 78 assertNotNull("MimePath should not be null", mimePath); 79 assertEquals("Wrong MimePath size", 0, mimePath.size()); 80 assertSame("Wrong empty MimePath", MimePath.EMPTY, mimePath); 81 } 82 83 for(String mimeType : valid) { 85 MimePath mimePath = MimePath.get(mimeType); 86 assertNotNull("MimePath should not be null", mimePath); 87 assertEquals("Wrong MimePath size", 1, mimePath.size()); 88 assertEquals("Wrong mime type", mimeType, mimePath.getMimeType(0)); 89 } 90 91 for(String mimeType : invalid) { 93 try { 94 MimePath mimePath = MimePath.get(mimeType); 95 fail("Should not create MimePath for an invalid mime type: '" + mimeType + "'"); 96 } catch (IllegalArgumentException iae) { 97 } 99 } 100 } 101 } 102 | Popular Tags |