Skip to content

Commit

Permalink
upgrade mockito to the latest available version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSnoozer committed Aug 10, 2017
1 parent 02d4905 commit 3c2e142
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -59,7 +59,7 @@

<jgit.version>4.5.2.201704071617-r</jgit.version>
<junit.version>4.12</junit.version>
<mockito.version>2.0.35-beta</mockito.version>
<mockito.version>2.8.47</mockito.version>

<fest-assert.version>1.4</fest-assert.version>
</properties>
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/org/mockito/internal/util/reflection/Whitebox.java
@@ -0,0 +1,40 @@
package org.mockito.internal.util.reflection;

import java.lang.reflect.Field;

@Deprecated
public class Whitebox {
public static void setInternalState(Object target, String field, Object value) {
Class<?> c = target.getClass();
try {
Field f = getFieldFromHierarchy(c, field);
f.setAccessible(true);
f.set(target, value);
} catch (Exception e) {
throw new RuntimeException("Unable to set internal state on a private field. Please report to mockito mailing list.", e);
}
}

private static Field getFieldFromHierarchy(Class<?> clazz, String field) {
Field f = getField(clazz, field);
while (f == null && clazz != Object.class) {
clazz = clazz.getSuperclass();
f = getField(clazz, field);
}
if (f == null) {
throw new RuntimeException(
"You want me to get this field: '" + field +
"' on this class: '" + clazz.getSimpleName() +
"' but this field is not declared withing hierarchy of this class!");
}
return f;
}

private static Field getField(Class<?> clazz, String field) {
try {
return clazz.getDeclaredField(field);
} catch (NoSuchFieldException e) {
return null;
}
}
}

0 comments on commit 3c2e142

Please sign in to comment.