Skip to content

Commit 3c2e142

Browse files
author
TheSnoozer
committed
upgrade mockito to the latest available version
1 parent 02d4905 commit 3c2e142

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<jgit.version>4.5.2.201704071617-r</jgit.version>
6161
<junit.version>4.12</junit.version>
62-
<mockito.version>2.0.35-beta</mockito.version>
62+
<mockito.version>2.8.47</mockito.version>
6363

6464
<fest-assert.version>1.4</fest-assert.version>
6565
</properties>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.mockito.internal.util.reflection;
2+
3+
import java.lang.reflect.Field;
4+
5+
@Deprecated
6+
public class Whitebox {
7+
public static void setInternalState(Object target, String field, Object value) {
8+
Class<?> c = target.getClass();
9+
try {
10+
Field f = getFieldFromHierarchy(c, field);
11+
f.setAccessible(true);
12+
f.set(target, value);
13+
} catch (Exception e) {
14+
throw new RuntimeException("Unable to set internal state on a private field. Please report to mockito mailing list.", e);
15+
}
16+
}
17+
18+
private static Field getFieldFromHierarchy(Class<?> clazz, String field) {
19+
Field f = getField(clazz, field);
20+
while (f == null && clazz != Object.class) {
21+
clazz = clazz.getSuperclass();
22+
f = getField(clazz, field);
23+
}
24+
if (f == null) {
25+
throw new RuntimeException(
26+
"You want me to get this field: '" + field +
27+
"' on this class: '" + clazz.getSimpleName() +
28+
"' but this field is not declared withing hierarchy of this class!");
29+
}
30+
return f;
31+
}
32+
33+
private static Field getField(Class<?> clazz, String field) {
34+
try {
35+
return clazz.getDeclaredField(field);
36+
} catch (NoSuchFieldException e) {
37+
return null;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)