Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
17   151   6   2.83
0   72   0.35   1.5
6     1  
4    
 
  TestDecorator       Line # 34 9 0% 1 0 100% 1.0
  TestDecorator.ISomeComponent       Line # 68 0 - 0 0 - -1.0
  TestDecorator.SomeComponent       Line # 80 3 0% 2 0 100% 1.0
  TestDecorator.ComponentDecorator       Line # 107 5 0% 3 0 100% 1.0
 
  (1)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // TestDecorator.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.decorator;
22   
23    import junit.framework.*;
24   
25    import org.perfectjpattern.core.api.structural.decorator.*;
26    import org.slf4j.*;
27   
28    /**
29    * Test Suite for <code>AbstarctDecorator</code> implementation.
30    *
31    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
32    * @version $Revision: 1.0 $ $Date: Nov 25, 2007 4:28:45 PM $
33    */
 
34    public class TestDecorator
35    extends TestCase
36    {
37    //------------------------------------------------------------------------
38    // public
39    //------------------------------------------------------------------------
 
40  1 toggle public void
41    testDecorator()
42    {
43  1 theLogger.debug("Step #1: Create a testing Component");
44  1 ISomeComponent myComponent = new SomeComponent();
45   
46  1 theLogger.debug("Step #2: Create Component Decorator");
47  1 IDecorator<ISomeComponent, ISomeComponent> myDecorator =
48    new ComponentDecorator(myComponent);
49   
50  1 theLogger.debug("Step #3: Use the Component reference of Decorator ");
51  1 myDecorator.getComponent().printValue("Hello World!");
52   
53  1 theLogger.debug("Running assertions");
54  1 assertTrue("printValue(...) must have been called in the Decorator",
55    ((ComponentDecorator) myDecorator).isCalled());
56   
57  1 assertTrue("printValue(...) must have been called in the Component",
58    ((SomeComponent) myComponent).isCalled());
59    }
60   
61    //------------------------------------------------------------------------
62    // inner classes
63    //------------------------------------------------------------------------
64    /**
65    * Definition of an example Component interface.
66    */
67    public static
 
68    interface ISomeComponent
69    {
70    //--------------------------------------------------------------------
71    public void
72    printValue(String aValue);
73    }
74   
75    //------------------------------------------------------------------------
76    /**
77    * Implementation of the interface defined above.
78    */
79    public static
 
80    class SomeComponent
81    implements ISomeComponent
82    {
83    //--------------------------------------------------------------------
 
84  1 toggle public void
85    printValue(String aValue)
86    {
87  1 theLogger.debug(aValue);
88   
89  1 theCalled = true;
90    }
91   
92    //--------------------------------------------------------------------
 
93  1 toggle public boolean
94    isCalled()
95    {
96  1 return theCalled;
97    }
98   
99    //--------------------------------------------------------------------
100    // members
101    //--------------------------------------------------------------------
102    private boolean theCalled;
103    }
104   
105    //------------------------------------------------------------------------
106    public static
 
107    class ComponentDecorator
108    extends AbstractDecorator<ISomeComponent, ISomeComponent>
109    {
110    //--------------------------------------------------------------------
 
111  1 toggle public
112    ComponentDecorator(ISomeComponent aComponent)
113    {
114  1 super(ISomeComponent.class, aComponent);
115    }
116   
117    //--------------------------------------------------------------------
 
118  1 toggle public void
119    printValue(String aValue)
120    {
121  1 theLogger.debug(aValue);
122   
123  1 theCalled = true;
124   
125  1 getDecorated().printValue(aValue);
126    }
127   
128    //--------------------------------------------------------------------
 
129  1 toggle public boolean
130    isCalled()
131    {
132  1 return theCalled;
133    }
134   
135    //--------------------------------------------------------------------
136    // members
137    //--------------------------------------------------------------------
138    private boolean theCalled;
139    }
140   
141    //------------------------------------------------------------------------
142    // members
143    //------------------------------------------------------------------------
144    /**
145    * Provides logging services for this class.
146    */
147    // CHECKSTYLE:OFF
148    private static final Logger theLogger = LoggerFactory.getLogger(
149    TestDecorator.class);
150    // CHECKSTYLE:ON
151    }