1package org.junit.runners;2import org.junit.BeforeClass;3import org.junit.Test;4import org.junit.runner.Runner;5import org.junit.runners.model.ClassWithADirectlyInheritedDefaultTestMethod;6import org.junit.runners.model.ClassWithADirectlyInheritedTestMethod;7import org.junit.runners.model.ClassWithADuallyInheritedTestMethod;8import org.junit.runners.model.ClassWithATestMethod;9import org.junit.runners.model.ClassWithATwiceInheritedDefaultTestMethod;10import org.junit.runners.model.ClassWithAnOverriddenDefaultTestMethod;11import org.junit.runners.model.ClassWithAnOverriddenDefaultTestMethodWithoutAnnotation;12import org.junit.runners.model.ClassWithAnOverriddenTestMethod;13import org.junit.runners.model.ClassWithAnOverriddenTestMethodWithoutAnnotation;14import org.junit.runners.model.ClassWithoutATestMethod;15import org.junit.runners.model.InitializationError;16import org.junit.runners.model.InterfaceWithADefaultTestMethod;17import org.junit.runners.model.InterfaceWithADirectlyInheritedDefaultTestMethod;18import org.junit.runners.model.InterfaceWithAnOverriddenDefaultTestMethod;19import org.junit.runners.model.InterfaceWithAnOverriddenDefaultTestMethodWithoutAnnotation;20import org.junit.runners.model.InterfaceWithoutATestMethod;21public class ProofingTheBehaviourOfBlockJUnit4ClassRunner_Tests22extends ProofingTheBehaviourOfRunners {23 protected static final String NOTHING = "%s: [%s] cannot run a test of [%s: %s].%n";24 protected static final String FINDING = "%s: [%s] can run a test of [%s: %s].%n";25 protected static final String FINDING2 = "%s: [%s] can run a test of [%s: %s, declard in %s].%n";26 @Override27 protected Runner getRunner(final Class<?> clazz)28 throws InitializationError {29 return new BlockJUnit4ClassRunner(clazz);30 }31 protected Class<? extends Runner> getRunnerClass() {32 return BlockJUnit4ClassRunner.class;33 }34 @BeforeClass35 public static void legend() {36 System.out.println("+--------------------------------------------------+");37 System.out.println("| Behaviour of BlockJUnit4ClassRunner |");38 System.out.println("| Legend: |");39 System.out.println("+--------------------------------------------------+");40 System.out.println("| [câ] Intended Construction Behaviour |");41 System.out.println("| [câ] Missing Construction Behaviour |");42 System.out.println("| [tâ] Intended Test Method Exploration Behaviour |");43 System.out.println("| [tâ] Missing Test Method Exploration Behaviour |");44 System.out.println("| |");45 System.out.println("| black ... can be created and execute tests |");46 System.out.println("| red ..... cannot be created and/or execute tests |");47 System.out.println("+--------------------------------------------------+");48 }49 @Test50 public void proofRunningOf_EmptyInterface()51 throws Exception {52 final Class<?> container = InterfaceWithoutATestMethod.class;53 this.proofClassRunnerWithInitializationErrorByNoConstructorAndNoTests(container);54 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an empty interface", container.getSimpleName());55 }56 @Test57 public void proofRunningOf_InterfaceWithDefaultTestMethod()58 throws Exception {59 final Class<?> container = InterfaceWithADefaultTestMethod.class;60 this.proofClassRunnerWithInitializationErrorByNoConstructor(container);61 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an interface with a default @Test method", container.getSimpleName());62 }63 @Test64 public void proofRunningOf_InterfaceWithDirectlyInheritedDefaultTestMethod()65 throws Exception {66 final Class<?> container = InterfaceWithADirectlyInheritedDefaultTestMethod.class;67 this.proofClassRunnerWithInitializationErrorByNoConstructorAndNoTests(container);68 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an interface inheriting a default @Test method", container.getSimpleName());69 }70 @Test71 public void proofRunningOf_EmptyClass()72 throws Exception {73 final Class<?> container = ClassWithoutATestMethod.class;74 this.proofClassRunnerWithInitializationErrorByNoTests(container);75 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an empty class", container.getSimpleName());76 }77 @Test78 public void proofRunningOf_ClassWithTestMethod()79 throws Exception {80 final Class<?> container = ClassWithATestMethod.class;81 this.proofJUnit4ClassRunnerWithASingleTest(container);82 System.out.format(FINDING, "câtâ", this.getRunnerClass(), "a class with a Test method", container.getSimpleName());83 }84 @Test85 public void proofRunningOf_ClassWithDirectlyInheritedTestMethod()86 throws Exception {87 final Class<?> container = ClassWithADirectlyInheritedTestMethod.class;88 final Class<?> effective = ClassWithATestMethod.class;89 this.proofJUnit4ClassRunnerWithASingleTest(container, effective);90 System.out.format(FINDING2, "câtâ", this.getRunnerClass(), "a class inheriting a @Test method", container.getSimpleName(), effective.getSimpleName());91 }92 @Test93 public void proofRunningOf_ClassWithDirectlyInheritedDefaultTestMethod()94 throws Exception {95 final Class<?> container = ClassWithADirectlyInheritedDefaultTestMethod.class;96 this.proofClassRunnerWithInitializationErrorByNoTests(container);97 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "a class inheriting a default @Test method", container.getSimpleName());98 }99 @Test100 public void proofRunningOf_InterfaceWithOverriddenDefaultTestMethod()101 throws Exception {102 final Class<?> container = InterfaceWithAnOverriddenDefaultTestMethod.class;103 this.proofClassRunnerWithInitializationErrorByNoConstructor(container);104 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an interface overriding a default @Test method", container.getSimpleName());105 }106 @Test107 public void proofRunningOf_InterfaceWithOverriddenDefaultTestMethodWithoutAnnotation()108 throws Exception {109 final Class<?> container = InterfaceWithAnOverriddenDefaultTestMethodWithoutAnnotation.class;110 this.proofClassRunnerWithInitializationErrorByNoConstructorAndNoTests(container);111 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "an interface overriding a default @Test method, without (!) @Test annotation",112 container.getSimpleName());113 }114 @Test115 public void proofRunningOf_ClassWithOverriddenDefaultTestMethod()116 throws Exception {117 final Class<?> container = ClassWithAnOverriddenDefaultTestMethod.class;118 this.proofJUnit4ClassRunnerWithASingleTest(container);119 System.out.format(FINDING, "câtâ", this.getRunnerClass(), "a class overriding a default @Test method", container.getSimpleName());120 }121 @Test122 public void proofRunningOf_ClassWithOverriddenDefaultTestMethodWithoutAnnotation()123 throws Exception {124 final Class<?> container = ClassWithAnOverriddenDefaultTestMethodWithoutAnnotation.class;125 this.proofClassRunnerWithInitializationErrorByNoTests(container);126 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "a class overriding a default @Test method, without (!) @Test annotation",127 container.getSimpleName());128 }129 @Test130 public void proofRunningOf_ClassWithOverriddenTestMethod()131 throws Exception {132 final Class<?> container = ClassWithAnOverriddenTestMethod.class;133 this.proofJUnit4ClassRunnerWithASingleTest(container);134 System.out.format(FINDING, "câtâ", this.getRunnerClass(), "a class overriding a @Test method", container.getSimpleName());135 }136 @Test137 public void proofRunningOf_ClassWithOverriddenTestMethodWithoutAnnotation()138 throws Exception {139 final Class<?> container = ClassWithAnOverriddenTestMethodWithoutAnnotation.class;140 final Class<?> effective = ClassWithAnOverriddenTestMethodWithoutAnnotation.class;141 this.proofJUnit4ClassRunnerWithASingleTest(container, effective);142 System.out.format(FINDING2, "câtâ", this.getRunnerClass(), "a class overriding a @Test method, without (!) @Test annotation", container.getSimpleName(),143 effective.getSimpleName());144 }145 @Test146 public void proofRunningOf_ClassWithTwiceInheritedDefaultTestMethod()147 throws Exception {148 final Class<?> container = ClassWithATwiceInheritedDefaultTestMethod.class;149 this.proofClassRunnerWithInitializationErrorByNoTests(container);150 System.err.format(NOTHING, "câtâ", this.getRunnerClass(), "a class inheriting a default @Test method twice (via super-class and interface)",151 container.getSimpleName());152 }153 @Test154 public void proofRunningOf_ClassWithDuallyInheritedTestMethod()155 throws Exception {156 final Class<?> container = ClassWithADuallyInheritedTestMethod.class;157 final Class<?> effective = ClassWithATestMethod.class;158 this.proofJUnit4ClassRunnerWithASingleTest(container, effective);159 System.out.format(FINDING2, "câtâ", this.getRunnerClass(), "a class inheriting a @Test method dually (via super-class and default via interface)",160 container, effective);161 }162}...