1 17 18 package javax.mail.internet; 19 20 import javax.mail.internet.HeaderTokenizer.Token; 21 22 import junit.framework.TestCase; 23 24 27 public class HeaderTokenizerTest extends TestCase { 28 public void testTokenizer() throws ParseException { 29 Token t; 30 HeaderTokenizer ht; 31 ht = 32 new HeaderTokenizer("To: \"Geronimo List\" <geronimo-dev@apache.org>, \n\r Geronimo User <geronimo-user@apache.org>"); 33 assertEquals("To", ht.peek().getValue()); 34 assertEquals("To", ht.next().getValue()); 35 assertEquals(":", ht.peek().getValue()); 36 assertEquals(":", ht.next().getValue()); 37 t = ht.next(); 38 assertEquals("Geronimo List", t.getValue()); 39 assertEquals(Token.QUOTEDSTRING, t.getType()); 40 assertEquals("<", ht.next().getValue()); 41 assertEquals("geronimo-dev", ht.next().getValue()); 42 assertEquals("@", ht.next().getValue()); 43 assertEquals("apache", ht.next().getValue()); 44 assertEquals(".", ht.next().getValue()); 45 assertEquals("org", ht.next().getValue()); 46 assertEquals(">", ht.next().getValue()); 47 assertEquals(",", ht.next().getValue()); 48 assertEquals("Geronimo", ht.next().getValue()); 49 assertEquals("User", ht.next().getValue()); 50 assertEquals("<", ht.next().getValue()); 51 assertEquals("geronimo-user", ht.next().getValue()); 52 assertEquals("@", ht.next().getValue()); 53 assertEquals("apache", ht.next().getValue()); 54 assertEquals(".", ht.next().getValue()); 55 assertEquals("org>", ht.getRemainder()); 56 assertEquals("org", ht.peek().getValue()); 57 assertEquals("org>", ht.getRemainder()); 58 assertEquals("org", ht.next().getValue()); 59 assertEquals(">", ht.next().getValue()); 60 assertEquals(Token.EOF, ht.next().getType()); 61 ht = new HeaderTokenizer(" "); 62 assertEquals(Token.EOF, ht.next().getType()); 63 ht = new HeaderTokenizer("J2EE"); 64 assertEquals("J2EE", ht.next().getValue()); 65 assertEquals(Token.EOF, ht.next().getType()); 66 doComment(true); 68 doComment(false); 69 } 70 public void doComment(boolean ignore) throws ParseException { 71 HeaderTokenizer ht; 72 Token t; 73 ht = 74 new HeaderTokenizer( 75 "Apache(Geronimo)J2EE", 76 HeaderTokenizer.RFC822, 77 ignore); 78 t = ht.next(); 79 assertEquals("Apache", t.getValue()); 80 assertEquals(Token.ATOM, t.getType()); 81 if (!ignore) { 82 t = ht.next(); 83 assertEquals("Geronimo", t.getValue()); 84 assertEquals(Token.COMMENT, t.getType()); 85 } 86 t = ht.next(); 87 assertEquals("J2EE", t.getValue()); 88 assertEquals(Token.ATOM, t.getType()); 89 assertEquals(Token.EOF, ht.next().getType()); 90 } 91 } 92 | Popular Tags |