package org.kohsuke.github;

import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;

import static org.hamcrest.Matchers.*;

/**
 * @author Kohsuke Kawaguchi
 */
public class BridgeMethodTest extends Assert {

    @Test
    public void testBridgeMethods() throws IOException {

        // Some would say this is redundant, given that bridge methods are so thin anyway
        // In the interest of maintaining binary compatibility, we'll do this anyway for a sampling of methods

        // Something odd here
        // verifyBridgeMethods(new GHCommit(), "getAuthor", GHCommit.GHAuthor.class, GitUser.class);
        // verifyBridgeMethods(new GHCommit(), "getCommitter", GHCommit.GHAuthor.class, GitUser.class);

        verifyBridgeMethods(GHIssue.class, "getCreatedAt", Date.class, String.class);
        verifyBridgeMethods(GHIssue.class, "getId", int.class, long.class, String.class);
        verifyBridgeMethods(GHIssue.class, "getUrl", String.class, URL.class);

        verifyBridgeMethods(GHOrganization.class, "getHtmlUrl", String.class, URL.class);
        verifyBridgeMethods(GHOrganization.class, "getId", int.class, long.class, String.class);
        verifyBridgeMethods(GHOrganization.class, "getUrl", String.class, URL.class);

        verifyBridgeMethods(GHRepository.class, "getCollaborators", GHPersonSet.class, Set.class);
        verifyBridgeMethods(GHRepository.class, "getHtmlUrl", String.class, URL.class);
        verifyBridgeMethods(GHRepository.class, "getId", int.class, long.class, String.class);
        verifyBridgeMethods(GHRepository.class, "getUrl", String.class, URL.class);

        verifyBridgeMethods(GHUser.class, "getFollows", GHPersonSet.class, Set.class);
        verifyBridgeMethods(GHUser.class, "getFollowers", GHPersonSet.class, Set.class);
        verifyBridgeMethods(GHUser.class, "getOrganizations", GHPersonSet.class, Set.class);
        verifyBridgeMethods(GHUser.class, "getId", int.class, long.class, String.class);

        verifyBridgeMethods(GHTeam.class, "getId", int.class, long.class, String.class);

        // verifyBridgeMethods(GitHub.class, "getMyself", GHMyself.class, GHUser.class);

    }

    void verifyBridgeMethods(@Nonnull Class<?> targetClass, @Nonnull String methodName, Class<?>... returnTypes) {
        List<Class<?>> foundMethods = new ArrayList<>();
        Method[] methods = targetClass.getMethods();
        for (Method method : methods) {
            if (method.getName().equalsIgnoreCase(methodName)) {
                // Bridge methods are only
                assertThat(method.getParameterCount(), equalTo(0));
                foundMethods.add(method.getReturnType());
            }
        }

        assertThat(foundMethods, containsInAnyOrder(returnTypes));
    }
}

@@ -1161,32 +1161,124 @@
 ass, URL.class);
+%0A        verifyBridgeMethods(GHIssue.class, %22comment%22, 1, void.class, GHIssueComment.class);
 %0A%0A        verify
@@ -2561,24 +2561,272 @@
 urnTypes) %7B%0A
+        verifyBridgeMethods(targetClass, methodName, 0, returnTypes);%0A    %7D%0A%0A    void verifyBridgeMethods(@Nonnull Class%3C?%3E targetClass,%0A            @Nonnull String methodName,%0A            int parameterCount,%0A            Class%3C?%3E... returnTypes) %7B%0A
         List
@@ -3028,122 +3028,59 @@
 ame)
-) %7B%0A                // Bridge methods are only%0A                assertThat(method.getParameterCount(), equalTo(0));
+ && method.getParameterCount() == parameterCount) %7B
 %0A   

Test that void bridge methods are created