| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 32 |
|
|
| 33 |
|
@see |
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
@version |
| 37 |
|
|
| 38 |
|
public |
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 2 |
Complexity Density: 0.09 |
|
| 39 |
|
class TestComposite |
| 40 |
|
extends TestCase |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 2 |
Complexity Density: 0.09 |
1
PASS
|
|
| 45 |
1
|
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 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
public static |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 96 |
|
interface ISomeComponent |
| 97 |
|
{ |
| 98 |
|
|
| 99 |
|
public void |
| 100 |
|
printValue(String aValue); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
private static |
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 108 |
|
class SomeComponent |
| 109 |
|
implements ISomeComponent |
| 110 |
|
{ |
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 112 |
4
|
public void ... |
| 113 |
|
printValue(String aValue) |
| 114 |
|
{ |
| 115 |
4
|
theLogger.debug(aValue); |
| 116 |
|
|
| 117 |
4
|
theCalled = true; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
4
|
public boolean... |
| 122 |
|
isCalled() |
| 123 |
|
{ |
| 124 |
4
|
return theCalled; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
private boolean theCalled; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
private final static Logger theLogger = LoggerFactory.getLogger( |
| 141 |
|
TestComposite.class); |
| 142 |
|
|
| 143 |
|
} |