Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
26   143   4   8.67
0   71   0.15   1
3     1.33  
3    
 
  TestComposite       Line # 39 23 0% 2 0 100% 1.0
  TestComposite.ISomeComponent       Line # 96 0 - 0 0 - -1.0
  TestComposite.SomeComponent       Line # 108 3 0% 2 0 100% 1.0
 
  (1)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // TestComposite.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.composite;
22   
23    import java.util.*;
24   
25    import junit.framework.*;
26   
27    import org.perfectjpattern.core.api.structural.composite.*;
28    import org.slf4j.*;
29   
30    /**
31    * Test Suite for the {@link Composite} implementation.
32    *
33    * @see Composite
34    *
35    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
36    * @version $Revision: 1.0 $ $Date: Nov 18, 2007 11:58:58 PM $
37    */
38    public
 
39    class TestComposite
40    extends TestCase
41    {
42    //------------------------------------------------------------------------
43    // public
44    //------------------------------------------------------------------------
 
45  1 toggle public void
46    testComposition()
47    {
48  1 theLogger.debug("Step #1: Create four Component elements");
49  1 ISomeComponent myComponent1 = new SomeComponent();
50  1 ISomeComponent myComponent2 = new SomeComponent();
51  1 ISomeComponent myComponent3 = new SomeComponent();
52  1 ISomeComponent myComponent4 = new SomeComponent();
53   
54  1 theLogger.debug("Step #2: Create Composite 1");
55  1 IComposite<ISomeComponent> myComposite1 = new Composite<ISomeComponent>(
56    ISomeComponent.class);
57   
58  1 theLogger.debug("Step #3: Create Composite 2");
59  1 IComposite<ISomeComponent> myComposite2 = new Composite<ISomeComponent>(
60    ISomeComponent.class);
61   
62  1 theLogger.debug("Step #4: Create compositions");
63  1 myComposite1.addAll(myComponent1, myComponent2);
64   
65  1 myComposite2.addAll(myComponent3, myComponent4, myComposite1.
66    getComponent());
67   
68  1 theLogger.debug("Step #5: Call a method on the Composite " +
69    "Component view that triggers execution over the whole " +
70    "composition");
71  1 myComposite2.getComponent().printValue("Hello World!");
72   
73  1 theLogger.debug("Prepare to run assertions");
74  1 Collection<ISomeComponent> myComponents = new ArrayList<
75    ISomeComponent>();
76  1 myComponents.add(myComponent1);
77  1 myComponents.add(myComponent2);
78  1 myComponents.add(myComponent3);
79  1 myComponents.add(myComponent4);
80   
81  1 theLogger.debug("Running assertions");
82  1 for (ISomeComponent myComponent : myComponents)
83    {
84  4 assertTrue("All Elements must have been called.", ((SomeComponent)
85    myComponent).isCalled());
86    }
87    }
88   
89    //------------------------------------------------------------------------
90    // inner classes
91    //------------------------------------------------------------------------
92    /**
93    * Definition of an example Component interface.
94    */
95    public static
 
96    interface ISomeComponent
97    {
98    //--------------------------------------------------------------------
99    public void
100    printValue(String aValue);
101    }
102   
103    //------------------------------------------------------------------------
104    /**
105    * Implementation of the interface defined above.
106    */
107    private static
 
108    class SomeComponent
109    implements ISomeComponent
110    {
111    //--------------------------------------------------------------------
 
112  4 toggle public void
113    printValue(String aValue)
114    {
115  4 theLogger.debug(aValue);
116   
117  4 theCalled = true;
118    }
119   
120    //--------------------------------------------------------------------
 
121  4 toggle public boolean
122    isCalled()
123    {
124  4 return theCalled;
125    }
126   
127    //--------------------------------------------------------------------
128    // members
129    //--------------------------------------------------------------------
130    private boolean theCalled;
131    }
132   
133    //------------------------------------------------------------------------
134    // members
135    //------------------------------------------------------------------------
136    /**
137    * Provides logging services for this class.
138    */
139    // CHECKSTYLE:OFF
140    private final static Logger theLogger = LoggerFactory.getLogger(
141    TestComposite.class);
142    // CHECKSTYLE:ON
143    }