public void testCheckAsBeginMethod() {
//--------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getMethod(
"beginNormal", new Class[]{Request.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getMethod(
"beginReturnsString", new Class[]{Request.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginReturnsString] "
+ "should return void and not [java.lang.String]",
e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getDeclaredMethod(
"beginProtected", new Class[]{Request.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginProtected] "
+ "should be declared public", e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getDeclaredMethod(
"beginPrivate", new Class[]{Request.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginPrivate] "
+ "should be declared public", e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getMethod(
"beginNoParam", new Class[]{});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginNoParam] must have 1 parameter(s), "
+ "but 0 parameter(s) were found", e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getMethod(
"beginWithTwoParams",
new Class[]{Request.class, Object.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginWithTwoParams] "
+ "must have 1 parameter(s), "
+ "but 2 parameter(s) were found", e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
//---------------------------------------------------------------------
try
{
Method method = MethodHolder.class.getMethod(
"beginWithStringParam", new Class[]{String.class});
TestCaseImplementChecker.checkAsBeginMethod(method);
fail(shouldNotHere());
}
catch (AssertionFailedError e)
{
assertEquals("The method [beginWithStringParam] "
+ "must accept [org.apache.cactus.Request] "
+ "as 1st parameter, but found a "
+ "[java.lang.String] parameter instead",
e.getMessage());
}
catch (Throwable t)
{
fail(shouldNotHere(t));
}
}
|