1   //----------------------------------------------------------------------
2   // 
3   // PerfectJPattern: "Design patterns are good but components are better!" 
4   // TestParameterlessSubject.java Copyright (c) 2009 Giovanni Azua Garcia
5   // bravegag@hotmail.com
6   //  
7   // This program is free software; you can redistribute it and/or
8   // modify it under the terms of the GNU General Public License
9   // as published by the Free Software Foundation; either version 3
10  // of the License, or (at your option) any later version.
11  //
12  // This program is distributed in the hope that it will be useful,
13  // but WITHOUT ANY WARRANTY; without even the implied warranty of
14  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  // GNU General Public License for more details.
16  //
17  // You should have received a copy of the GNU General Public License
18  // along with this program; if not, see <http://www.gnu.org/licenses/>.
19  //
20  //----------------------------------------------------------------------
21  package org.perfectjpattern.core.behavioral.observer;
22  
23  import junit.framework.*;
24  
25  import org.perfectjpattern.core.api.behavioral.observer.*;
26  import org.perfectjpattern.core.api.behavioral.observer.data.*;
27  
28  /**
29   * Test suite for the {@link ParameterlessSubject} implementation
30   * 
31   * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
32   * @version $Revision: 1.0 $Date: Feb 13, 2009 10:03:09 PM $
33   */
34  public 
35  class TestParameterlessSubject
36  extends TestCase
37  {
38      //------------------------------------------------------------------------
39      // public
40      //------------------------------------------------------------------------
41      @SuppressWarnings("unchecked")
42      public void 
43      testParameterlessSubject()
44      {
45          IObserver<NullEventData> myObserver1 = new TestNullEventDataObserver();
46          IObserver<NullEventData> myObserver2 = new TestNullEventDataObserver();
47          
48          ParameterlessSubject mySubject = new ParameterlessSubject();
49          mySubject.attach(myObserver1, myObserver2);
50          mySubject.notifyObservers();
51          
52          assertEquals("ParameterlessSubject did not work as expected", 2, 
53              theCallCount);
54      }
55      
56      //------------------------------------------------------------------------
57      // inner classes
58      //------------------------------------------------------------------------
59      /**
60       * Concrete <code>IObserver&lt;NullEventData&gt;</code> implementation
61       */
62      private static final 
63      class TestNullEventDataObserver 
64      implements IObserver<NullEventData> 
65      {
66          //---------------------------------------------------------------------
67          public void 
68          update(NullEventData anEventData) 
69          {
70              theCallCount++;
71          }
72      }
73      
74      //------------------------------------------------------------------------
75      // members
76      //------------------------------------------------------------------------
77      private static int theCallCount = 0;
78  }