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.monitor.it;
22  
23  import junit.framework.Assert;
24  import junit.framework.TestCase;
25  import org.jdtaus.core.monitor.TaskEventSource;
26  import org.jdtaus.core.monitor.TaskListener;
27  
28  /**
29   * Testcase for {@code TaskEventSource} implementations.
30   *
31   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
32   * @version $JDTAUS: TaskEventSourceTest.java 8692 2012-10-01 14:16:57Z schulte $
33   */
34  public class TaskEventSourceTest extends TestCase
35  {
36      //--TaskEventSourceTest-----------------------------------------------------
37  
38      /** Implementation to test. */
39      private TaskEventSource source;
40  
41      /**
42       * Gets the {@code TaskEventSource} implementation tests are performed with.
43       *
44       * @return the {@code TaskEventSource} implementation tests are performed
45       * with.
46       */
47      public TaskEventSource getTaskEventSource()
48      {
49          return this.source;
50      }
51  
52      /**
53       * Sets the {@code TaskEventSource} implementation tests are performed with.
54       *
55       * @param value the {@code TaskEventSource} implementation to perform tests
56       * with.
57       */
58      public final void setTaskEventSource( final TaskEventSource value )
59      {
60          this.source = value;
61      }
62  
63      //-----------------------------------------------------TaskEventSourceTest--
64      //--Tests-------------------------------------------------------------------
65  
66      /**
67       * Tests the {@link TaskEventSource#addTaskListener(TaskListener)} method to
68       * handle {@code null} listener values correctly by throwing a corresponding
69       * {@code NullPointerException}.
70       */
71      public void testAddTaskListener() throws Exception
72      {
73          assert this.getTaskEventSource() != null;
74  
75          try
76          {
77              this.getTaskEventSource().addTaskListener( null );
78              throw new AssertionError();
79          }
80          catch ( NullPointerException e )
81          {
82              Assert.assertNotNull( e.getMessage() );
83              System.out.println( e.toString() );
84          }
85  
86      }
87  
88      /**
89       * Tests the {@link TaskEventSource#removeTaskListener(TaskListener)} method
90       * to handle {@code null} listener values correctly by throwing a
91       * corresponding {@code NullPointerException}.
92       */
93      public void testRemoveTaskListener() throws Exception
94      {
95          assert this.getTaskEventSource() != null;
96  
97          try
98          {
99              this.getTaskEventSource().removeTaskListener( null );
100             throw new AssertionError();
101         }
102         catch ( NullPointerException e )
103         {
104             Assert.assertNotNull( e.getMessage() );
105             System.out.println( e.toString() );
106         }
107 
108     }
109 
110     /**
111      * Tests the {@link TaskEventSource#getTaskListeners()} method to not
112      * return a {@code null} value instead of an empty array when no listeners
113      * are registered.
114      */
115     public void testGetTaskListeners() throws Exception
116     {
117         assert this.getTaskEventSource() != null;
118 
119         Assert.assertNotNull( this.getTaskEventSource().getTaskListeners() );
120     }
121 
122     //-------------------------------------------------------------------Tests--
123 }