| 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.adapter; |
| 22 |
|
|
| 23 |
|
import java.util.*; |
| 24 |
|
|
| 25 |
|
import junit.framework.*; |
| 26 |
|
|
| 27 |
|
import org.perfectjpattern.core.api.structural.adapter.*; |
| 28 |
|
import org.slf4j.*; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@link@link |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
@version |
| 37 |
|
|
| 38 |
|
public |
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 4 |
Complexity Density: 0.24 |
|
| 39 |
|
class TestExactMatchAdapter |
| 40 |
|
extends TestCase |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.43 |
1
PASS
|
|
| 45 |
1
|
public void... |
| 46 |
|
testValidate() |
| 47 |
|
{ |
| 48 |
1
|
IAdaptingStrategy myExactMatchStrategy = |
| 49 |
|
new ExactMatchAdaptingStrategy(); |
| 50 |
|
|
| 51 |
1
|
try |
| 52 |
|
{ |
| 53 |
1
|
myExactMatchStrategy.validate(ITargetInterface.class, |
| 54 |
|
new GoodAdaptee(), new Object()); |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
} |
| 58 |
|
catch (NoSuchMethodError anException) |
| 59 |
|
{ |
| 60 |
0
|
fail("ExactMatch did not validate a good adaptee properly"); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
1
|
try |
| 64 |
|
{ |
| 65 |
1
|
myExactMatchStrategy.validate(ITargetInterface.class, |
| 66 |
|
new BadAdaptee(), new Object()); |
| 67 |
|
|
| 68 |
0
|
fail("ExactMatch did not validate a bad adaptee properly"); |
| 69 |
|
} |
| 70 |
|
catch (NoSuchMethodError anException) |
| 71 |
|
{ |
| 72 |
|
|
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 77 |
1
|
public void... |
| 78 |
|
testAdapter() |
| 79 |
|
{ |
| 80 |
1
|
theLogger.debug("Step #1: Create Adapter with default " + |
| 81 |
|
"AdaptingStrategy"); |
| 82 |
1
|
IAdapter<ITargetInterface, GoodAdaptee> myAdapter = new Adapter< |
| 83 |
|
ITargetInterface, GoodAdaptee>(ITargetInterface.class, |
| 84 |
|
new GoodAdaptee()); |
| 85 |
|
|
| 86 |
1
|
theLogger.debug("Step #2: Acquire the Target (Componet type view " + |
| 87 |
|
"of the Adaptee)"); |
| 88 |
1
|
ITargetInterface myTarget = myAdapter.getTarget(); |
| 89 |
|
|
| 90 |
1
|
theLogger.debug("Step #3: Invoke methods on the Target interface"); |
| 91 |
1
|
myTarget.method1("argument", Integer.valueOf(1)); |
| 92 |
1
|
myTarget.method2(); |
| 93 |
|
|
| 94 |
1
|
theLogger.debug("Step #4: Run assertions"); |
| 95 |
1
|
assertEquals("Adapter did not invoke method1 as expected", |
| 96 |
|
theInvokations.get(0), "method1"); |
| 97 |
1
|
assertEquals("Adapter did not invoke method2 as expected", |
| 98 |
|
theInvokations.get(1), "method2"); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
private |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 105 |
|
interface ITargetInterface |
| 106 |
|
{ |
| 107 |
|
|
| 108 |
|
public void |
| 109 |
|
method1(String anArgument1, Integer anArgument2); |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
public void |
| 113 |
|
method2(); |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
public boolean |
| 117 |
|
isSupported(); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
private |
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 4 |
Complexity Density: 1.33 |
|
| 122 |
|
class GoodAdaptee |
| 123 |
|
{ |
| 124 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 125 |
1
|
public void... |
| 126 |
|
method1(String anArgument1, Integer anArgument2) |
| 127 |
|
{ |
| 128 |
1
|
theInvokations.add("method1"); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 132 |
1
|
public void... |
| 133 |
|
method2() |
| 134 |
|
{ |
| 135 |
1
|
theInvokations.add("method2"); |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
0
|
public boolean... |
| 140 |
|
isSupported() |
| 141 |
|
{ |
| 142 |
0
|
return true; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 146 |
0
|
public void... |
| 147 |
|
method3(Double anArgument1) |
| 148 |
|
{ |
| 149 |
|
|
| 150 |
|
} |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
private |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: - |
|
| 155 |
|
class BadAdaptee |
| 156 |
|
{ |
| 157 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 158 |
0
|
public void... |
| 159 |
|
method1(String anArgument1, Integer anArgument2) |
| 160 |
|
{ |
| 161 |
|
|
| 162 |
|
} |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
private final List<String> theInvokations = new ArrayList<String>(); |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
private final static Logger theLogger = LoggerFactory.getLogger( |
| 175 |
|
TestExactMatchAdapter.class); |
| 176 |
|
|
| 177 |
|
} |