package io.amaze.bench.shared.helper;

import org.junit.Test;

import javax.validation.constraints.Null;
import java.lang.reflect.Method;

import static io.amaze.bench.shared.helper.ReflectionHelper.findAtMostOneAnnotatedMethod;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * Created on 3/1/16.
 *
 * @author Florent Weber (florent.weber@gmail.com)
 */
public final class ReflectionHelperTest {

    @Test
    public void find_no_annotated_method_returns_null() {
        Method method = findAtMostOneAnnotatedMethod(NoAnnotatedMethod.class, Null.class);
        assertNull(method);
    }

    @Test
    public void find_single_annotated_method_works() {
        Method method = findAtMostOneAnnotatedMethod(SingleAnnotatedMethod.class, Null.class);
        assertNotNull(method);
        assertThat(method.getName(), is("annotated"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void find_two_annotated_methods_throws() {
        findAtMostOneAnnotatedMethod(TwoAnnotatedMethods.class, Null.class);
    }

    private interface NoAnnotatedMethod {
        void test();
    }

    private interface SingleAnnotatedMethod {
        @Null
        void annotated();

        void test();
    }

    private interface TwoAnnotatedMethods {
        @Null
        void annotated1();

        @Null
        void annotated2();
    }

}
@@ -71,37 +71,156 @@
 java
-x.validation.constraints.Null
+.lang.annotation.ElementType;%0Aimport java.lang.annotation.Retention;%0Aimport java.lang.annotation.RetentionPolicy;%0Aimport java.lang.annotation.Target
 ;%0Aim
@@ -809,36 +809,46 @@
 edMethod.class, 
-Null
+TestAnnotation
 .class);%0A       
@@ -1014,36 +1014,46 @@
 edMethod.class, 
-Null
+TestAnnotation
 .class);%0A       
@@ -1313,20 +1313,151 @@
 ss, 
-Null.class);
+TestAnnotation.class);%0A    %7D%0A%0A    @Retention(RetentionPolicy.RUNTIME)%0A    @Target(%7BElementType.METHOD%7D)%0A    public @interface TestAnnotation %7B%0A
 %0A   
@@ -1577,36 +1577,46 @@
 thod %7B%0A        @
-Null
+TestAnnotation
 %0A        void an
@@ -1700,36 +1700,46 @@
 hods %7B%0A        @
-Null
+TestAnnotation
 %0A        void an
@@ -1760,20 +1760,30 @@
        @
-Null
+TestAnnotation
 %0A       

Fix test