HHH-6677 skip @BeforeClassOnce / @AfterClassOnce if test is ignored

This commit is contained in:
Strong Liu 2011-09-27 01:00:49 +08:00
parent 3fe833456b
commit bd54fe08f5
1 changed files with 34 additions and 7 deletions

View File

@ -71,8 +71,32 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
return testClassMetadata;
}
private Boolean isAllTestsIgnored = null;
private boolean isAllTestsIgnored() {
if ( isAllTestsIgnored == null ) {
if ( computeTestMethods().isEmpty() ) {
isAllTestsIgnored = true;
}
else {
isAllTestsIgnored = true;
for ( FrameworkMethod method : computeTestMethods() ) {
Ignore ignore = method.getAnnotation( Ignore.class );
if ( ignore == null ) {
isAllTestsIgnored = false;
break;
}
}
}
}
return isAllTestsIgnored;
}
@Override
protected Statement withBeforeClasses(Statement statement) {
if ( isAllTestsIgnored() ) {
return super.withBeforeClasses( statement );
}
return new BeforeClassCallbackHandler(
this,
super.withBeforeClasses( statement )
@ -81,6 +105,9 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
@Override
protected Statement withAfterClasses(Statement statement) {
if ( isAllTestsIgnored() ) {
return super.withAfterClasses( statement );
}
return new AfterClassCallbackHandler(
this,
super.withAfterClasses( statement )