Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » [javadoc | source]
    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package javax.mail;
   19   import junit.framework.TestCase;
   20   /**
   21    * @version $Revision $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $
   22    */
   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   }

Save This Page
Home » glassfish-v2ur2-b04-src » javax » mail » [javadoc | source]