package de.skuzzle.inject.async.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

import de.skuzzle.inject.async.util.MethodVisitor;

public class MethodVisitorTest {

    public static class SuperClass {

        public static void staticSuperMethod() {

        }

        public void publicSuperMethod() {

        }

        private void privateSuperMethod() {

        }
    }

    public static class SubClass extends SuperClass {
        public void pulicMethod() {

        }

        private void privateMethod() {

        }
    }

    @Before
    public void setUp() throws Exception {}

    @Test
    public void testVisitAll() throws Exception {
        final Set<Method> visited = new HashSet<>();
        MethodVisitor.forEachMemberMethod(SubClass.class, visited::add);
        assertEquals(4, visited.size());
    }

    @Test
    public void testVisitAllObject() throws Exception {
        final Set<Method> visited = new HashSet<>();
        MethodVisitor.forEachMemberMethod(Object.class, visited::add);
        assertEquals(0, visited.size());
    }

    @Test
    public void testPrivateCtor() throws Exception {
        final Constructor<MethodVisitor> ctor = MethodVisitor.class.getDeclaredConstructor();
        ctor.setAccessible(true);
        ctor.newInstance();
        assertTrue(Modifier.isPrivate(ctor.getModifiers()));
    }
}

@@ -329,60 +329,8 @@
 t;%0A%0A
-import de.skuzzle.inject.async.util.MethodVisitor;%0A%0A
 publ
@@ -787,16 +787,21 @@
 eption %7B
+%0A    
 %7D%0A%0A    @
@@ -1397,16 +1397,33 @@
 or.class
+%0A                
 .getDecl
@@ -1569,11 +1569,248 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testVisitStatic() throws Exception %7B%0A        final Set%3CMethod%3E visited = new HashSet%3C%3E();%0A        MethodVisitor.forEachStaticMethod(SubClass.class, visited::add);%0A        assertEquals(1, visited.size());%0A    %7D
 %0A%7D%0A

Add test case