blob: 515ee7a9b8d1bfbf5b1230a7acd41a947ca1de7e [file] [log] [blame]
/*
* 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
*
* https://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.directory.api.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
/**
* Test case for {@link MethodUtils}.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@Execution(ExecutionMode.CONCURRENT)
public class MethodUtilsTest
{
private static class TestClass
{
@SuppressWarnings("unused")
public static void methodA( String str )
{
}
@SuppressWarnings("unused")
public static void methodB( Collection<?> c )
{
}
}
@Test
public void testSameBehaviourOfStandardGetMethod()
{
Method m1 = null;
Method m2 = null;
try
{
m1 = TestClass.class.getMethod( "methodA", new Class[]
{ String.class } );
}
catch ( SecurityException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( NoSuchMethodException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
m2 = MethodUtils.getAssignmentCompatibleMethod( TestClass.class, "methodA", new Class[]
{ String.class } );
}
catch ( NoSuchMethodException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
assertEquals( m1, m2 );
}
@Test
public void testNewBehaviourOfAssignmentCompatibleGetMethod()
{
Method m2 = null;
try
{
TestClass.class.getMethod( "methodB", new Class[]
{ ArrayList.class } );
fail( "We should not have come here." );
}
catch ( SecurityException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( NoSuchMethodException e )
{
assertNotNull( e );
}
try
{
m2 = MethodUtils.getAssignmentCompatibleMethod( TestClass.class, "methodB", new Class[]
{ ArrayList.class } );
}
catch ( NoSuchMethodException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
assertNotNull( m2 );
}
}