| 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.decorator; |
| 22 |
|
|
| 23 |
|
import junit.framework.*; |
| 24 |
|
|
| 25 |
|
import org.perfectjpattern.core.api.structural.decorator.*; |
| 26 |
|
import org.slf4j.*; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@author |
| 32 |
|
@version |
| 33 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 34 |
|
public class TestDecorator |
| 35 |
|
extends TestCase |
| 36 |
|
{ |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
| 40 |
1
|
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 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
public static |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 68 |
|
interface ISomeComponent |
| 69 |
|
{ |
| 70 |
|
|
| 71 |
|
public void |
| 72 |
|
printValue(String aValue); |
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
public static |
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 80 |
|
class SomeComponent |
| 81 |
|
implements ISomeComponent |
| 82 |
|
{ |
| 83 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 84 |
1
|
public void ... |
| 85 |
|
printValue(String aValue) |
| 86 |
|
{ |
| 87 |
1
|
theLogger.debug(aValue); |
| 88 |
|
|
| 89 |
1
|
theCalled = true; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
1
|
public boolean... |
| 94 |
|
isCalled() |
| 95 |
|
{ |
| 96 |
1
|
return theCalled; |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
private boolean theCalled; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
public static |
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 107 |
|
class ComponentDecorator |
| 108 |
|
extends AbstractDecorator<ISomeComponent, ISomeComponent> |
| 109 |
|
{ |
| 110 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 111 |
1
|
public ... |
| 112 |
|
ComponentDecorator(ISomeComponent aComponent) |
| 113 |
|
{ |
| 114 |
1
|
super(ISomeComponent.class, aComponent); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 118 |
1
|
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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
1
|
public boolean... |
| 130 |
|
isCalled() |
| 131 |
|
{ |
| 132 |
1
|
return theCalled; |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
private boolean theCalled; |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
private static final Logger theLogger = LoggerFactory.getLogger( |
| 149 |
|
TestDecorator.class); |
| 150 |
|
|
| 151 |
|
} |