1 package org.wamblee.reflection;
3 import static junit.framework.Assert.*;
5 import java.lang.reflect.Field;
6 import java.lang.reflect.Method;
11 public class ReflectionUtilsTest {
13 public static interface X {
17 public static class X2 {
29 public static class X3 extends X2 {
35 public static class X4 extends X2 {
41 public static class X5 extends X2 {
46 @Test(expected = IllegalArgumentException.class)
47 public void testGetAllMethodsInterface() {
48 ReflectionUtils.getAllMethods(X.class);
52 public void testBasicClass() {
53 List<Method> res = ReflectionUtils
54 .getAllMethods(X2.class, Object.class);
55 assertEquals(2, res.size());
59 public void testInheritanceAdditionalMethod() {
60 List<Method> res = ReflectionUtils
61 .getAllMethods(X3.class, Object.class);
62 assertEquals(3, res.size());
66 public void testInheritanceOverriddenMethod() {
67 List<Method> res = ReflectionUtils
68 .getAllMethods(X4.class, Object.class);
69 assertEquals(2, res.size());
70 for (Method method : res) {
71 if (method.getName().equals("x")) {
72 assertEquals(X4.class, method.getDeclaringClass());
77 @Test(expected = IllegalArgumentException.class)
78 public void testGetAllFieldsInterface() {
79 ReflectionUtils.getAllFields(X.class);
83 public void testFieldsFromBasicClass() {
84 List<Field> fields = ReflectionUtils.getAllFields(X2.class);
85 assertEquals(1, fields.size());
86 assertEquals("bla", fields.get(0).getName());
89 public void testFieldsWithInheritance() {
90 List<Field> fields = ReflectionUtils.getAllFields(X5.class);
91 assertEquals(3, fields.size());