Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jan 17, 2013
Juha Paananen run onceBefores/After also for spec superclasses bcbea32
@jannehietamaki jannehietamaki Merge pull request #12 from raimohanska/master
Run onceBefore/onceAfter methods also for spec superclasses
bb599e3
View
16 jdave-core/src/java/jdave/runner/SpecRunner.java
@@ -51,12 +51,18 @@ protected Behavior newBehavior(Method method,
runOnceAfters(specType);
}
- private <T extends Specification<?>> void runOnceBefores(Class<T> specType) {
- runPublicStaticVoidMethodNamed("onceBefore", specType);
+ private <T extends Specification<?>> void runOnceBefores(Class<?> specType) {
+ if (specType != null) {
+ runOnceBefores(specType.getSuperclass());
+ runPublicStaticVoidMethodNamed("onceBefore", specType);
+ }
}
- private <T extends Specification<?>> void runOnceAfters(Class<T> specType) {
- runPublicStaticVoidMethodNamed("onceAfter", specType);
+ private <T extends Specification<?>> void runOnceAfters(Class<?> specType) {
+ if (specType != null) {
+ runPublicStaticVoidMethodNamed("onceAfter", specType);
+ runOnceAfters(specType.getSuperclass());
+ }
}
private <T> void runPublicStaticVoidMethodNamed(String name, Class<T> specType) {
@@ -113,4 +119,4 @@ private boolean annotationIsPresent(Class<?> clazz, Class<? extends Annotation>
}
return false;
}
-}
+}
View
26 jdave-core/src/test/jdave/runner/SpecRunnerTest.java
@@ -138,6 +138,20 @@ public void testShouldCallOnceAfterExactlyOnce() throws Exception {
}
@Test
+ public void testShouldCallSuperClassOnceBeforeExactlyOnce() throws Exception {
+ BaseSpec.onceBeforeCalled = 0;
+ runner.run(BooleanSpec.class, new SpecVisitorAdapter(new ResultsAdapter()));
+ assertEquals(1, BaseSpec.onceBeforeCalled);
+ }
+
+ @Test
+ public void testShouldCallSuperClassOnceAfterExactlyOnce() throws Exception {
+ BaseSpec.onceAfterCalled = 0;
+ runner.run(BooleanSpec.class, new SpecVisitorAdapter(new ResultsAdapter()));
+ assertEquals(1, BaseSpec.onceAfterCalled);
+ }
+
+ @Test
public void testShouldCallOnceAfterEvenIfContextDestroyCrashes() {
SpecWithCrashingContextDestroy.onceAfterCalled = 0;
runner.run(SpecWithCrashingContextDestroy.class, new SpecVisitorAdapter(
@@ -174,6 +188,16 @@ public void testAllowsContextWithoutCreateMethod() throws Exception {
public static class BaseSpec extends Specification<Boolean> {
public static List<String> actualCalls = new ArrayList<String>();
+ public static int onceBeforeCalled;
+ public static int onceAfterCalled;
+
+ public static void onceBefore() {
+ onceBeforeCalled++;
+ }
+
+ public static void onceAfter() {
+ onceAfterCalled++;
+ }
public class CommonContext {
public void anyBehavior() {
@@ -368,4 +392,4 @@ public void someBehavior() {
}
}
}
-}
+}

No commit comments for this range

Something went wrong with that request. Please try again.