1 17 18 package javax.mail; 19 import junit.framework.TestCase; 20 23 public class MessagingExceptionTest extends TestCase { 24 private RuntimeException d; 25 private MessagingException c; 26 private MessagingException b; 27 private MessagingException a; 28 public MessagingExceptionTest(String name) { 29 super(name); 30 } 31 protected void setUp() throws Exception { 32 super.setUp(); 33 a = new MessagingException("A"); 34 b = new MessagingException("B"); 35 c = new MessagingException("C"); 36 d = new RuntimeException("D"); 37 } 38 public void testMessagingExceptionString() { 39 assertEquals("A", a.getMessage()); 40 } 41 public void testNextException() { 42 assertTrue(a.setNextException(b)); 43 assertEquals(b, a.getNextException()); 44 assertTrue(a.setNextException(c)); 45 assertEquals(b, a.getNextException()); 46 assertEquals(c, b.getNextException()); 47 String message = a.getMessage(); 48 int ap = message.indexOf("A"); 49 int bp = message.indexOf("B"); 50 int cp = message.indexOf("C"); 51 assertTrue("A does not contain 'A'", ap != -1); 52 assertTrue("B does not contain 'B'", bp != -1); 53 assertTrue("C does not contain 'C'", cp != -1); 54 } 55 public void testNextExceptionWrong() { 56 assertTrue(a.setNextException(d)); 57 assertFalse(a.setNextException(b)); 58 } 59 public void testNextExceptionWrong2() { 60 assertTrue(a.setNextException(d)); 61 assertFalse(a.setNextException(b)); 62 } 63 public void testMessagingExceptionStringException() { 64 MessagingException x = new MessagingException("X", a); 65 assertEquals("X (javax.mail.MessagingException: A)", x.getMessage()); 66 assertEquals(a, x.getNextException()); 67 assertEquals(a, x.getCause()); 68 } 69 } 70 | Popular Tags |