View Javadoc

1   /*
2    *  jDTAUS Core Test Suite
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *
20   */
21  package org.jdtaus.core.lang.it;
22  
23  import junit.framework.Assert;
24  import junit.framework.TestCase;
25  import org.jdtaus.core.lang.ExceptionEventSource;
26  
27  /**
28   * Testcase for {@code ExceptionEventSource} implementations.
29   *
30   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
31   * @version $JDTAUS: ExceptionEventSourceTest.java 8692 2012-10-01 14:16:57Z schulte $
32   */
33  public abstract class ExceptionEventSourceTest extends TestCase
34  {
35      //--ExceptionEventSourceTest------------------------------------------------
36  
37      /**
38       * Gets the {@code ExceptionEventSource} implementation tests are performed
39       * with.
40       *
41       * @return the {@code ExceptionEventSource} implementation tests are
42       * performed with.
43       */
44      public abstract ExceptionEventSource getExceptionEventSource();
45  
46      //------------------------------------------------ExceptionEventSourceTest--
47      //--Tests-------------------------------------------------------------------
48  
49      /**
50       * Tests the
51       * {@link ExceptionEventSource#addExceptionListener(ExceptionListener)} and
52       * {@link ExceptionEventSource#removeExceptionListener(ExceptionListener)}
53       * methods to correctly handle {@code null} arguments by throwing a
54       * corresponding {@code NullPointerException}.
55       */
56      public void testNullArguments() throws Exception
57      {
58          assert this.getExceptionEventSource() != null;
59  
60          try
61          {
62              this.getExceptionEventSource().addExceptionListener( null );
63              throw new AssertionError();
64          }
65          catch ( NullPointerException e )
66          {
67              Assert.assertNotNull( e.getMessage() );
68              System.out.println( e.toString() );
69          }
70  
71          try
72          {
73              this.getExceptionEventSource().removeExceptionListener( null );
74              throw new AssertionError();
75          }
76          catch ( NullPointerException e )
77          {
78              Assert.assertNotNull( e.getMessage() );
79              System.out.println( e.toString() );
80          }
81  
82      }
83  
84      //-------------------------------------------------------------------Tests--
85  }