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,16 +71,43 @@ public class CustomRunner extends BlockJUnit4ClassRunner {
return testClassMetadata;
}
@Override
protected Statement withBeforeClasses(Statement statement) {
return new BeforeClassCallbackHandler(
this,
super.withBeforeClasses( statement )
);
}
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 )
);
}
@Override
protected Statement withAfterClasses(Statement statement) {
if ( isAllTestsIgnored() ) {
return super.withAfterClasses( statement );
}
return new AfterClassCallbackHandler(
this,
super.withAfterClasses( statement )