|
| 1 | +package org.junit.tests.experimental.theories; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Assume; |
| 5 | +import org.junit.Test; |
| 6 | +import org.junit.experimental.theories.DataPoint; |
| 7 | +import org.junit.experimental.theories.Theories; |
| 8 | +import org.junit.experimental.theories.Theory; |
| 9 | +import org.junit.runner.JUnitCore; |
| 10 | +import org.junit.runner.Request; |
| 11 | +import org.junit.runner.Result; |
| 12 | +import org.junit.runner.RunWith; |
| 13 | +import org.junit.runner.Runner; |
| 14 | +import org.junit.runners.model.InitializationError; |
| 15 | + |
| 16 | +@RunWith(Theories.class) |
| 17 | +public class AssumingInTheoriesTest { |
| 18 | + |
| 19 | + @Test |
| 20 | + public void noTheoryAnnotationMeansAssumeShouldIgnore() { |
| 21 | + Assume.assumeTrue(false); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void theoryMeansOnlyAssumeShouldFail() throws InitializationError { |
| 26 | + JUnitCore junitRunner = new JUnitCore(); |
| 27 | + Runner theoryRunner = new Theories(TheoryWithNoUnassumedParameters.class); |
| 28 | + Request request = Request.runner(theoryRunner); |
| 29 | + Result result = junitRunner.run(request); |
| 30 | + Assert.assertEquals(1, result.getFailureCount()); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Simple class that SHOULD fail because no parameters are met. |
| 35 | + */ |
| 36 | + public static class TheoryWithNoUnassumedParameters { |
| 37 | + |
| 38 | + @DataPoint |
| 39 | + public final static boolean FALSE = false; |
| 40 | + |
| 41 | + @Theory |
| 42 | + public void theoryWithNoUnassumedParameters(boolean value) { |
| 43 | + Assume.assumeTrue(value); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments