Skip to content

Instantly share code, notes, and snippets.

@shelaf
Last active June 12, 2017 12:28
Show Gist options
  • Save shelaf/885fe42695fef50b3103fc1e5a8b8aa3 to your computer and use it in GitHub Desktop.
Save shelaf/885fe42695fef50b3103fc1e5a8b8aa3 to your computer and use it in GitHub Desktop.
Javaでオーバーライドされた元のメソッドを呼ぶ
Class clazz = Application.class;
Method method = clazz.getDeclaredMethod("validate", String.class);
method.setAccessible(true);
method.invoke(null, "1w");
Field field = clazz.getSuperclass().getDeclaredField("validation");
field.setAccessible(true);
Validation v = (Validation) field.get(null);
assertEquals(1, v.errorsMap().size());
Method m = v.getClass().getDeclaredMethod("clear");
m.invoke(null);
assertEquals(0, v.errorsMap().size());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment