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 8743 2012-10-07 03:06:20Z schulte $
32   */
33  public abstract class ExceptionEventSourceTest extends TestCase
34  {
35      //--ExceptionEventSourceTest------------------------------------------------
36  
37      /** Creates a new {@code ExceptionEventSourceTest} instance. */
38      public ExceptionEventSourceTest()
39      {
40          super();
41      }
42  
43      /**
44       * Gets the {@code ExceptionEventSource} implementation tests are performed
45       * with.
46       *
47       * @return the {@code ExceptionEventSource} implementation tests are
48       * performed with.
49       */
50      public abstract ExceptionEventSource getExceptionEventSource();
51  
52      //------------------------------------------------ExceptionEventSourceTest--
53      //--Tests-------------------------------------------------------------------
54  
55      /**
56       * Tests the
57       * {@link ExceptionEventSource#addExceptionListener(ExceptionListener)} and
58       * {@link ExceptionEventSource#removeExceptionListener(ExceptionListener)}
59       * methods to correctly handle {@code null} arguments by throwing a
60       * corresponding {@code NullPointerException}.
61       */
62      public void testNullArguments() throws Exception
63      {
64          assert this.getExceptionEventSource() != null;
65  
66          try
67          {
68              this.getExceptionEventSource().addExceptionListener( null );
69              throw new AssertionError();
70          }
71          catch ( final NullPointerException e )
72          {
73              Assert.assertNotNull( e.getMessage() );
74              System.out.println( e.toString() );
75          }
76  
77          try
78          {
79              this.getExceptionEventSource().removeExceptionListener( null );
80              throw new AssertionError();
81          }
82          catch ( final NullPointerException e )
83          {
84              Assert.assertNotNull( e.getMessage() );
85              System.out.println( e.toString() );
86          }
87  
88      }
89  
90      //-------------------------------------------------------------------Tests--
91  }