package org.osgl.inject;

/*-
 * #%L
 * OSGL Genie
 * %%
 * Copyright (C) 2017 OSGL (Open Source General Library)
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.junit.Test;
import org.osgl.inject.annotation.InjectTag;
import osgl.ut.TestBase;

import java.lang.annotation.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import javax.inject.Qualifier;

public class BeanSpecTest extends TestBase {

    @Test
    public void testTaggedAnnotation() throws Exception {
        Constructor<LeatherSmoother.Host> constructor = LeatherSmoother.Host.class.getConstructor(LeatherSmoother.class);
        Annotation[] annotations = constructor.getParameterAnnotations()[0];
        Type paramType = constructor.getGenericParameterTypes()[0];
        BeanSpec spec = BeanSpec.of(paramType, annotations, Genie.create());
        eq(1, spec.taggedAnnotations(Qualifier.class).length);
        eq(0, spec.taggedAnnotations(InjectTag.class).length);
        eq(0, spec.taggedAnnotations(Retention.class).length);
        eq(0, spec.taggedAnnotations(Target.class).length);
        eq(0, spec.taggedAnnotations(Inherited.class).length);
        eq(0, spec.taggedAnnotations(Documented.class).length);
    }

}

@@ -846,16 +846,49 @@
 ructor;%0A
+import java.lang.reflect.Method;%0A
 import j
@@ -1783,10 +1783,1134 @@
 %0A    %7D%0A%0A
+    public static class Foo %7B%0A        public void getVoid() %7B%7D%0A%0A        public String getString() %7B%0A            return %22%22;%0A        %7D%0A%0A        public String getStringWithArgs(int i) %7B%0A            return %22%22;%0A        %7D%0A%0A        public String setString() %7B%0A            return %22%22;%0A        %7D%0A%0A        private String getPrivate() %7B%0A            return %22%22;%0A        %7D%0A%0A        public static String getStatic() %7B%0A            return %22%22;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testIsGetter() throws Exception %7B%0A        yes(isGetter(%22getString%22));%0A        no(isGetter(%22getVoid%22));%0A        no(isGetter(%22getStringWithArgs%22));%0A        no(isGetter(%22setString%22));%0A        no(isGetter(%22getPrivate%22));%0A        no(isGetter(%22getStatic%22));%0A    %7D%0A%0A    private boolean isGetter(String methodName) %7B%0A        Method method = getMethod(methodName);%0A        return BeanSpec.isGetter(method);%0A    %7D%0A%0A    private Method getMethod(String methodName) %7B%0A        for (Method method : Foo.class.getDeclaredMethods()) %7B%0A            if (method.getName().equals(methodName)) %7B%0A                return method;%0A            %7D%0A        %7D%0A        return null;%0A    %7D%0A%0A
 %7D%0A

add Unit test for BeanSpec.isGetter(Method) method