Skip to content

Commit 3682517

Browse files
committed
OP_1.1.0, test apache#4 completed, spy removed, MyOptionsMethodTracker implemented
1 parent c86ec80 commit 3682517

File tree

4 files changed

+142
-143
lines changed

4 files changed

+142
-143
lines changed

openjpa-lib/src/test/java/org/apache/openjpa/lib/util/MyOptionsConfigurer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import org.apache.openjpa.lib.util.MyOptionsTest.PropertyState;
66
import org.apache.openjpa.lib.util.MyOptionsTest.TestState;
77

8+
import java.lang.reflect.InvocationTargetException;
89
import java.util.Set;
910

10-
import static org.mockito.Mockito.spy;
11-
1211
public class MyOptionsConfigurer {
1312

1413
public static final String PRIMITIVE_VALUE = "1";
@@ -100,8 +99,8 @@ private void createObj() {
10099
Class deepestClass = getDeepestClass();
101100
DeepestInterface deepest;
102101
try {
103-
deepest = spy((DeepestInterface) deepestClass.newInstance());
104-
} catch (InstantiationException | IllegalAccessException e) {
102+
deepest = (DeepestInterface) deepestClass.getConstructor(boolean.class).newInstance(false);
103+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
105104
throw new RuntimeException(e);
106105
}
107106

@@ -118,16 +117,19 @@ private void createObj() {
118117
if (intermediateClass == null)
119118
throw new IllegalStateException("#TODO: not implemented combination of B1, B2, B3, B4");
120119

120+
IntermediateInterface top;
121+
IntermediateInterface middle;
121122
try {
122-
IntermediateInterface top = spy((IntermediateInterface) intermediateClass.newInstance());
123-
IntermediateInterface middle = spy((IntermediateInterface) intermediateClass.newInstance());
123+
top = (IntermediateInterface) intermediateClass.getConstructor(boolean.class).newInstance(false);
124+
middle = (IntermediateInterface) intermediateClass.getConstructor(boolean.class).newInstance(false);
124125
testState.obj = top;
125126
if (testState.c1 == C1_intermediate_instances_are_null.NON_NULL_INTERMEDIATE_INSTANCES) {
126127
top.intermediateSetDeeper(middle);
127128
if (testState.c2 == C2_last_instance_is_null.NON_NULL_LAST_INSTANCE)
128-
top.intermediateSetDeepest(deepest);
129+
middle.intermediateSetDeepest(deepest);
129130
}
130-
} catch (InstantiationException | IllegalAccessException e) {
131+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
132+
InvocationTargetException e) {
131133
throw new RuntimeException(e);
132134
}
133135
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.apache.openjpa.lib.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class MyOptionsMethodTracker {
7+
public static List<String> methodCallList = new ArrayList<>();
8+
9+
public static void addMethod(String newString) {
10+
methodCallList.add(newString);
11+
}
12+
13+
public static boolean verify(String methodName) {
14+
return methodCallList.contains(methodName);
15+
}
16+
}

openjpa-lib/src/test/java/org/apache/openjpa/lib/util/MyOptionsObjects.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.apache.openjpa.lib.util;
22

3+
import static org.apache.openjpa.lib.util.MyOptionsMethodTracker.addMethod;
4+
35
public class MyOptionsObjects {
46

57
public interface AnyDeepInterface {
68
DeepestInterface intermediateGetDeepest();
79
}
810

911
public interface DeepestInterface {
10-
1112
int deepestPrimitiveAttribute(String id);
1213

1314
String deepestStringAttribute(String id);
@@ -20,8 +21,6 @@ public interface IntermediateInterface {
2021

2122
void intermediateSetDeeper(IntermediateInterface lower);
2223

23-
DeepestInterface intermediateGetDeepest();
24-
2524
void intermediateSetDeepest(DeepestInterface deepest);
2625
}
2726

@@ -30,21 +29,31 @@ public static class ObjectWithYYNNType1 implements IntermediateInterface, AnyDee
3029
private DeepestObjectType1 deepest;
3130

3231
private ObjectWithYYNNType1() {
32+
addMethod("new IntermediateInterface");
33+
}
34+
35+
public ObjectWithYYNNType1(boolean track) {
36+
if (track)
37+
addMethod("new IntermediateInterface");
3338
}
3439

3540
public ObjectWithYYNNType1 getDeeper() {
41+
addMethod("getDeeper");
3642
return deeper;
3743
}
3844

3945
public void setDeeper(ObjectWithYYNNType1 deeper) {
46+
addMethod("setDeeper");
4047
this.deeper = deeper;
4148
}
4249

4350
public DeepestObjectType1 getDeepest() {
51+
addMethod("getDeepest");
4452
return deepest;
4553
}
4654

4755
public void setDeepest(DeepestObjectType1 deepest) {
56+
addMethod("setDeepest");
4857
this.deepest = deepest;
4958
}
5059

@@ -65,7 +74,7 @@ public DeepestInterface intermediateGetDeepest() {
6574

6675
@Override
6776
public void intermediateSetDeepest(DeepestInterface deepest) {
68-
this.deeper.setDeepest((DeepestObjectType1) deepest);
77+
this.deepest = (DeepestObjectType1) deepest;
6978
}
7079
}
7180

@@ -74,21 +83,31 @@ public static class ObjectWithYYNYType1 implements IntermediateInterface, AnyDee
7483
private DeepestObjectType1 deepest;
7584

7685
public ObjectWithYYNYType1() {
86+
addMethod("new IntermediateInterface");
87+
}
88+
89+
public ObjectWithYYNYType1(boolean track) {
90+
if (track)
91+
addMethod("new IntermediateInterface");
7792
}
7893

7994
public ObjectWithYYNYType1 getDeeper() {
95+
addMethod("getDeeper");
8096
return deeper;
8197
}
8298

8399
public void setDeeper(ObjectWithYYNYType1 deeper) {
100+
addMethod("setDeeper");
84101
this.deeper = deeper;
85102
}
86103

87104
public DeepestObjectType1 getDeepest() {
105+
addMethod("getDeepest");
88106
return deepest;
89107
}
90108

91109
public void setDeepest(DeepestObjectType1 deepest) {
110+
addMethod("setDeepest");
92111
this.deepest = deepest;
93112
}
94113

@@ -109,7 +128,7 @@ public DeepestInterface intermediateGetDeepest() {
109128

110129
@Override
111130
public void intermediateSetDeepest(DeepestInterface deepest) {
112-
this.deeper.setDeepest((DeepestObjectType1) deepest);
131+
this.deepest = (DeepestObjectType1) deepest;
113132
}
114133
}
115134

@@ -122,17 +141,26 @@ public static class DeepestObjectType1 implements DeepestInterface, AnyDeepInter
122141
private int PrimitiveAttribute1;
123142

124143
public DeepestObjectType1() {
144+
addMethod("new DeepestInterface");
145+
}
146+
147+
public DeepestObjectType1(boolean track){
148+
if (track)
149+
addMethod("new DeepestInterface");
125150
}
126151

127152
public void setPrimitiveAttribute1(int primitiveAttribute1) {
153+
addMethod("setPrimitiveAttribute1");
128154
PrimitiveAttribute1 = primitiveAttribute1;
129155
}
130156

131157
public void setStringAttribute1(String stringAttribute1) {
158+
addMethod("setStringAttribute1");
132159
StringAttribute1 = stringAttribute1;
133160
}
134161

135162
public void setSpecialClassAttribute1(SpecialClass specialClassAttribute1) {
163+
addMethod("setSpecialClassAttribute1");
136164
SpecialClassAttribute1 = specialClassAttribute1;
137165
}
138166

0 commit comments

Comments
 (0)