Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #97 from Fiouz/JENKINS-39362
[FIXED JENKINS-39362] Replace mockito-all by mockito-core
- Loading branch information
Showing
2 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/hudson/plugins/promoted_builds/TestingFrameworkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package hudson.plugins.promoted_builds; | ||
|
||
import org.hamcrest.BaseMatcher; | ||
import org.hamcrest.Description; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runners.model.Statement; | ||
import org.jvnet.hudson.test.Issue; | ||
|
||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* This is not a regular unit test: it validates the testing framework by making sure we can rely on it | ||
*/ | ||
public class TestingFrameworkTest { | ||
|
||
/** | ||
* Allow special processing of AssertionError | ||
*/ | ||
private static class TestMonitoringRule implements TestRule { | ||
|
||
boolean expectFailure = false; | ||
|
||
@Override | ||
public Statement apply(final Statement base, final org.junit.runner.Description description) { | ||
return new Statement() { | ||
@Override | ||
public void evaluate() throws Throwable { | ||
boolean testSuccess = false; | ||
try { | ||
base.evaluate(); | ||
testSuccess = true; | ||
} catch (AssertionError e) { | ||
if (!expectFailure) { | ||
throw e; | ||
} | ||
// expected failure, discard assertion error | ||
} | ||
if (expectFailure && testSuccess) { | ||
// if we get here, that means we are not processing a failing test (the purpose of this class) | ||
throw new AssertionError("This must test the processing of failed Matcher, not the well-being of system under tests"); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
@Rule | ||
public TestMonitoringRule rule = new TestMonitoringRule(); | ||
|
||
@Test | ||
@Issue("JENKINS-39362") | ||
public void testNegativeMatcher() throws Throwable { | ||
rule.expectFailure = true; | ||
assertThat(null, new BaseMatcher<Object>() { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Always false matcher"); | ||
} | ||
@Override | ||
public boolean matches(Object item) { | ||
// returning false indicates the test failure | ||
// JENKINS-39362 is caused by errors during the processing of that failure | ||
return false; | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testPositiveMatcher() throws Throwable { | ||
assertThat(null, new BaseMatcher<Object>() { | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("Always true matcher"); | ||
} | ||
@Override | ||
public boolean matches(Object item) { | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
} |