| 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.behavioral.chainofresponsibility; |
| 22 |
|
|
| 23 |
|
import junit.framework.*; |
| 24 |
|
|
| 25 |
|
import org.slf4j.*; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@author |
| 31 |
|
@version |
| 32 |
|
|
| 33 |
|
public |
|
|
|
| 100% |
Uncovered Elements: 0 (30) |
Complexity: 4 |
Complexity Density: 0.15 |
|
| 34 |
|
class TestAbstractParameterlessHandler |
| 35 |
|
extends TestCase |
| 36 |
|
{ |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
| 43 |
1
|
public void ... |
| 44 |
|
testChainSuccessfullyInvoked() |
| 45 |
|
{ |
| 46 |
1
|
theLogger.debug("Running assertions ... "); |
| 47 |
|
|
| 48 |
|
|
| 49 |
1
|
assertTrue("First element was never invoked.", theFirst.isCalled()); |
| 50 |
1
|
assertTrue("Second element was never invoked.", theSecond.isCalled()); |
| 51 |
1
|
assertTrue("Third element was never invoked.", theThird.isCalled()); |
| 52 |
|
|
| 53 |
1
|
theLogger.debug("Completed test"); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
| 60 |
1
|
public void ... |
| 61 |
|
testChainInvokedInCorrectOrder() |
| 62 |
|
{ |
| 63 |
1
|
theLogger.debug("Running assertions ... "); |
| 64 |
|
|
| 65 |
|
|
| 66 |
1
|
assertEquals("First element was not correctly invoked first.", |
| 67 |
|
1, theFirst.getIndex()); |
| 68 |
1
|
assertEquals("Second element was not correctly invoked second.", 2, |
| 69 |
|
theSecond.getIndex()); |
| 70 |
1
|
assertEquals("Third element was not correctly invoked third.", 3, |
| 71 |
|
theThird.getIndex()); |
| 72 |
|
|
| 73 |
1
|
theLogger.debug("Completed test"); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 79 |
2
|
@Override... |
| 80 |
|
protected void |
| 81 |
|
setUp() |
| 82 |
|
throws Exception |
| 83 |
|
{ |
| 84 |
2
|
super.setUp(); |
| 85 |
|
|
| 86 |
2
|
theLogger.debug( |
| 87 |
|
"Creating ChainOfResponsibility test fixture ... "); |
| 88 |
|
|
| 89 |
|
|
| 90 |
2
|
TestChainBasicElement.resetCounter(); |
| 91 |
|
|
| 92 |
2
|
fixture(); |
| 93 |
|
|
| 94 |
2
|
theLogger.debug( |
| 95 |
|
"Completed ChainOfResponsibility test fixture."); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
| 104 |
2
|
protected void ... |
| 105 |
|
fixture() |
| 106 |
|
{ |
| 107 |
2
|
theLogger.debug("Step #1 := Create handlers"); |
| 108 |
2
|
theSecond = new TestChainBasicElement(); |
| 109 |
2
|
theFirst = new TestChainBasicElement(theSecond); |
| 110 |
2
|
theThird = new TestChainBasicElement(); |
| 111 |
|
|
| 112 |
2
|
theLogger.debug("Step #2 := Associate all chain handlers"); |
| 113 |
2
|
theSecond.setSuccessor(theThird); |
| 114 |
|
|
| 115 |
2
|
theLogger.debug("Step #3 := Modify default IChainStrategy"); |
| 116 |
2
|
theFirst.setChainStrategy(AllHandleStrategy.getInstance()); |
| 117 |
2
|
theSecond.setChainStrategy(AllHandleStrategy.getInstance()); |
| 118 |
|
|
| 119 |
2
|
theLogger.debug("Step #4 := Trigger the chain execution"); |
| 120 |
2
|
theFirst.start(); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
private static |
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 6 |
Complexity Density: 1 |
|
| 130 |
|
class TestChainBasicElement |
| 131 |
|
extends AbstractParameterlessHandler |
| 132 |
|
{ |
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
4
|
public... |
| 135 |
|
TestChainBasicElement() |
| 136 |
|
{ |
| 137 |
4
|
super(); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 141 |
2
|
public... |
| 142 |
|
TestChainBasicElement(TestChainBasicElement aSuccessor) |
| 143 |
|
{ |
| 144 |
2
|
super(aSuccessor); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
2
|
public static void ... |
| 152 |
|
resetCounter() |
| 153 |
|
{ |
| 154 |
2
|
TestChainBasicElement.theCounter = 0; |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 158 |
6
|
public void ... |
| 159 |
|
handle() |
| 160 |
|
{ |
| 161 |
|
|
| 162 |
6
|
theIndex = ++theCounter; |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 166 |
3
|
public final boolean... |
| 167 |
|
isCalled() |
| 168 |
|
{ |
| 169 |
3
|
return theIndex != -1; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
@return |
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 176 |
3
|
public final int ... |
| 177 |
|
getIndex() |
| 178 |
|
{ |
| 179 |
3
|
return theIndex; |
| 180 |
|
} |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
private static int theCounter = 0; |
| 186 |
|
private int theIndex = -1; |
| 187 |
|
} |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
private TestChainBasicElement theFirst = null; |
| 196 |
|
private TestChainBasicElement theSecond = null; |
| 197 |
|
private TestChainBasicElement theThird = null; |
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
private final Logger theLogger = LoggerFactory.getLogger(this.getClass()); |
| 203 |
|
} |