/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */
package org.apache.xbean.finder;

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;

import org.acme.NotAnnotated;
import org.acme.bar.FullyAnnotated;
import org.acme.bar.ParamA;
import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.Test;

public class AnnotatedParametersTest {

    @Test
    public void testFindAnnotatedMethodParameters() {
        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
        List<Parameter<Method>> methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);
        assertEquals(1, methodParameters.size());
        Parameter<Method> parameter = methodParameters.get(0);
        assertEquals(0, parameter.getIndex());
        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
        assertEquals("setMoreStrings", parameter.getDeclaringExecutable().getName());
        assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);
        assertEquals(String[][].class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
        assertTrue(parameter.isAnnotationPresent(ParamA.class));
    }

    @Test
    public void testFindAnnotatedConstructorParameters() {
        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
        List<Parameter<Constructor<?>>> constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);
        assertEquals(1, constructorParameters.size());
        Parameter<Constructor<?>> parameter = constructorParameters.get(0);
        assertEquals(0, parameter.getIndex());
        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
        assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);
        assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
        assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()[1]);
        assertTrue(parameter.isAnnotationPresent(ParamA.class));
    }
}
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */
package org.apache.xbean.finder;

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;

import org.acme.NotAnnotated;
import org.acme.bar.FullyAnnotated;
import org.acme.bar.ParamA;
import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.Test;

public class AnnotatedParametersTest {

    @Test
    public void testFindAnnotatedMethodParameters() {
        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
        List<Parameter<Method>> methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);
        assertEquals(1, methodParameters.size());
        Parameter<Method> parameter = methodParameters.get(0);
        assertEquals(0, parameter.getIndex());
        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
        assertEquals("setMoreStrings", parameter.getDeclaringExecutable().getName());
        assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);
        assertEquals(String[][].class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
        assertTrue(parameter.isAnnotationPresent(ParamA.class));
    }

    @Test
    public void testFindAnnotatedConstructorParameters() {
        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));
        List<Parameter<Constructor<?>>> constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);
        assertEquals(1, constructorParameters.size());
        Parameter<Constructor<?>> parameter = constructorParameters.get(0);
        assertEquals(0, parameter.getIndex());
        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());
        assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);
        assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()[0]);
        assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()[1]);
        assertTrue(parameter.isAnnotationPresent(ParamA.class));
    }
}

@@ -3071,3078 +3071,4 @@
 %7D%0A%7D%0A
-/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0Apackage org.apache.xbean.finder;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport java.lang.reflect.Constructor;%0Aimport java.lang.reflect.Method;%0Aimport java.util.List;%0A%0Aimport org.acme.NotAnnotated;%0Aimport org.acme.bar.FullyAnnotated;%0Aimport org.acme.bar.ParamA;%0Aimport org.apache.xbean.finder.archive.ClassesArchive;%0Aimport org.junit.Test;%0A%0Apublic class AnnotatedParametersTest %7B%0A%0A    @Test%0A    public void testFindAnnotatedMethodParameters() %7B%0A        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));%0A        List%3CParameter%3CMethod%3E%3E methodParameters = finder.findAnnotatedMethodParameters(ParamA.class);%0A        assertEquals(1, methodParameters.size());%0A        Parameter%3CMethod%3E parameter = methodParameters.get(0);%0A        assertEquals(0, parameter.getIndex());%0A        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());%0A        assertEquals(%22setMoreStrings%22, parameter.getDeclaringExecutable().getName());%0A        assertEquals(1, parameter.getDeclaringExecutable().getParameterTypes().length);%0A        assertEquals(String%5B%5D%5B%5D.class, parameter.getDeclaringExecutable().getParameterTypes()%5B0%5D);%0A        assertTrue(parameter.isAnnotationPresent(ParamA.class));%0A    %7D%0A%0A    @Test%0A    public void testFindAnnotatedConstructorParameters() %7B%0A        final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(FullyAnnotated.class, NotAnnotated.class));%0A        List%3CParameter%3CConstructor%3C?%3E%3E%3E constructorParameters = finder.findAnnotatedConstructorParameters(ParamA.class);%0A        assertEquals(1, constructorParameters.size());%0A        Parameter%3CConstructor%3C?%3E%3E parameter = constructorParameters.get(0);%0A        assertEquals(0, parameter.getIndex());%0A        assertEquals(FullyAnnotated.class, parameter.getDeclaringExecutable().getDeclaringClass());%0A        assertEquals(2, parameter.getDeclaringExecutable().getParameterTypes().length);%0A        assertEquals(String.class, parameter.getDeclaringExecutable().getParameterTypes()%5B0%5D);%0A        assertEquals(int.class, parameter.getDeclaringExecutable().getParameterTypes()%5B1%5D);%0A        assertTrue(parameter.isAnnotationPresent(ParamA.class));%0A    %7D%0A%7D%0A

clean up of one more double-patch mistake