public abstract class ExtensibleTestCase extends UnitilsJUnit4
{
protected Object CallByName( Object object, String method, Object... args )
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException
{
int argsCount = args.length;
for ( Method m : object.getClass().getDeclaredMethods() )
{
if ( m.getName().equals( method )&&argsCount == m.getParameterTypes().length )
{
for (int i=0;i<args.length;i++)
{
if (!m.getParameterTypes()[i].isInstance(args[i] ))
throw new NoSuchMethodException( method);
}
m.setAccessible( true );
return m.invoke( object, args );
}
}
throw new NoSuchMethodException( method);
}
}
测试私有方法
最新推荐文章于 2024-02-06 14:23:07 发布