Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
18   141   5   3.6
0   67   0.28   1.67
5     1  
3    
 
  TestProxy       Line # 35 13 0% 1 0 100% 1.0
  TestProxy.ISomeComponent       Line # 76 0 - 0 0 - -1.0
  TestProxy.SomeComponent       Line # 92 5 0% 4 0 100% 1.0
 
  (1)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // TestProxy.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.structural.proxy;
22   
23    import junit.framework.*;
24   
25    import org.perfectjpattern.core.api.structural.proxy.*;
26    import org.slf4j.*;
27   
28    /**
29    * Test suite for the {@link AbstractProxy} implementation
30    *
31    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
32    * @version $Revision: 1.0 $Date: Jun 18, 2008 10:57:21 PM $
33    */
34    public
 
35    class TestProxy
36    extends TestCase
37    {
38    //------------------------------------------------------------------------
39    // public
40    //------------------------------------------------------------------------
 
41  1 toggle public void
42    testProxying()
43    {
44  1 theLogger.debug("Step #1: Create component and proxy");
45  1 SomeComponent mySubject = new SomeComponent();
46  1 IProxy<ISomeComponent> myProxy = new AbstractProxy<
47    ISomeComponent>(ISomeComponent.class, mySubject)
48    {
49    // empty
50    };
51   
52  1 theLogger.debug("Step #2: Make sure that the 'Subject' is correct");
53  1 assertSame("IProxy.getSubject not correctly implemented", mySubject,
54    myProxy.getRealSubject());
55   
56  1 theLogger.debug("Step #3: Get reference to proxied component");
57  1 ISomeComponent myComponent = myProxy.getSubject();
58   
59  1 theLogger.debug("Step #4: Call methods through the proxied component");
60  1 myComponent.method1("Hello proxy world!");
61  1 myComponent.method2();
62   
63  1 theLogger.debug("Running assertions");
64  1 assertTrue("method1 was not called", mySubject.isMethod1Called());
65   
66  1 assertTrue("method2 was not called", mySubject.isMethod2Called());
67    }
68   
69    //------------------------------------------------------------------------
70    // inner classes
71    //------------------------------------------------------------------------
72    /**
73    * Definition of an example Component interface.
74    */
75    public static
 
76    interface ISomeComponent
77    {
78    //--------------------------------------------------------------------
79    public void
80    method1(String aValue);
81   
82    //--------------------------------------------------------------------
83    public void
84    method2();
85    }
86   
87    //------------------------------------------------------------------------
88    /**
89    * Implementation of the interface defined above.
90    */
91    private static
 
92    class SomeComponent
93    implements ISomeComponent
94    {
95    //--------------------------------------------------------------------
 
96  1 toggle public void
97    method1(String aValue)
98    {
99  1 theLogger.debug(aValue);
100   
101  1 theMethod1Called = true;
102    }
103   
104    //--------------------------------------------------------------------
 
105  1 toggle public void
106    method2()
107    {
108  1 theMethod2Called = true;
109    }
110   
111    //--------------------------------------------------------------------
 
112  1 toggle public boolean
113    isMethod1Called()
114    {
115  1 return theMethod1Called;
116    }
117   
118    //--------------------------------------------------------------------
 
119  1 toggle public boolean
120    isMethod2Called()
121    {
122  1 return theMethod2Called;
123    }
124   
125    //--------------------------------------------------------------------
126    // members
127    //--------------------------------------------------------------------
128    private boolean theMethod1Called;
129    private boolean theMethod2Called;
130    }
131   
132    //------------------------------------------------------------------------
133    // members
134    //------------------------------------------------------------------------
135    /**
136    * Provides logging services for this class.
137    */
138    // CHECKSTYLE:OFF
139    private final static Logger theLogger = LoggerFactory.getLogger(TestProxy.class);
140    // CHECKSTYLE:ON
141    }