--- /dev/null
+package org.wamblee.reflection;
+
+import static junit.framework.Assert.*;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.junit.Test;
+
+public class ReflectionUtilsTest {
+
+ public static interface X {
+ void x();
+ }
+
+ public static class X2 {
+ private int bla;
+
+ public void x() {
+
+ }
+
+ private void y() {
+
+ }
+ }
+
+ public static class X3 extends X2 {
+ public void z() {
+
+ }
+ }
+
+ public static class X4 extends X2 {
+ public void x() {
+
+ }
+ }
+
+ public static class X5 extends X2 {
+ private String field;
+ private int g;
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetAllMethodsInterface() {
+ ReflectionUtils.getAllMethods(X.class);
+ }
+
+ @Test
+ public void testBasicClass() {
+ List<Method> res = ReflectionUtils.getAllMethods(X2.class, Object.class);
+ assertEquals(2, res.size());
+ }
+
+ @Test
+ public void testInheritanceAdditionalMethod() {
+ List<Method> res = ReflectionUtils.getAllMethods(X3.class, Object.class);
+ assertEquals(3, res.size());
+ }
+
+ @Test
+ public void testInheritanceOverriddenMethod() {
+ List<Method> res = ReflectionUtils.getAllMethods(X4.class, Object.class);
+ assertEquals(2, res.size());
+ for (Method method : res) {
+ if (method.getName().equals("x")) {
+ assertEquals(X4.class, method.getDeclaringClass());
+ }
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetAllFieldsInterface() {
+ ReflectionUtils.getAllFields(X.class);
+ }
+
+ @Test
+ public void testFieldsFromBasicClass() {
+ List<Field> fields = ReflectionUtils.getAllFields(X2.class);
+ assertEquals(1, fields.size());
+ assertEquals("bla", fields.get(0).getName());
+ }
+
+ public void testFieldsWithInheritance() {
+ List<Field> fields = ReflectionUtils.getAllFields(X5.class);
+ assertEquals(3, fields.size());
+ }
+}