下面列出了org.junit.runner.Description#EMPTY 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void verifyFailureStackTraceIsTruncated() throws Exception {
InstrumentationResultPrinter intrResultPrinter = new InstrumentationResultPrinter();
intrResultPrinter.testNum = 1;
Failure testFailure = new Failure(Description.EMPTY, new Exception(getVeryLargeString()));
intrResultPrinter.testFailure(testFailure);
int testResultTraceLength =
intrResultPrinter.testResult.getString(REPORT_KEY_STACK).length() - 1;
assertTrue(
String.format(
"The stack trace length: %s, exceeds the max: %s",
testResultTraceLength, MAX_TRACE_SIZE),
testResultTraceLength <= MAX_TRACE_SIZE);
}
@Test
public void shouldReplaceException() throws Exception {
//given
RuntimeException actualExc = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, actualExc);
//when
hacker.appendWarnings(failure, "unused stubbing");
//then
assertEquals(ExceptionIncludingMockitoWarnings.class, failure.getException().getClass());
assertEquals(actualExc, failure.getException().getCause());
Assertions.assertThat(actualExc.getStackTrace()).isEqualTo(failure.getException().getStackTrace());
}
@Test
public void shouldAppendWarning() throws Exception {
Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
//when
hacker.appendWarnings(failure, "unused stubbing blah");
//then
assertContains("unused stubbing blah", failure.getException().getMessage());
}
@Test
public void shouldNotAppendWhenNoWarnings() throws Exception {
RuntimeException ex = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, ex);
//when
hacker.appendWarnings(failure, "");
//then
assertEquals(ex, failure.getException());
}
@Test
public void shouldNotAppendWhenNullWarnings() throws Exception {
RuntimeException ex = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, ex);
//when
hacker.appendWarnings(failure, null);
//then
assertEquals(ex, failure.getException());
}
@Test
public void shouldPrintTheWarningSoICanSeeIt() throws Exception {
Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
//when
hacker.appendWarnings(failure, "unused stubbing blah");
//then
System.out.println(failure.getException());
}
@Test
public void shouldReplaceException() throws Exception {
//given
RuntimeException actualExc = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, actualExc);
//when
hacker.appendWarnings(failure, "unused stubbing");
//then
assertEquals(ExceptionIncludingMockitoWarnings.class, failure.getException().getClass());
assertEquals(actualExc, failure.getException().getCause());
Assertions.assertThat(actualExc.getStackTrace()).isEqualTo(failure.getException().getStackTrace());
}
@Test
public void shouldAppendWarning() throws Exception {
Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
//when
hacker.appendWarnings(failure, "unused stubbing blah");
//then
assertContains("unused stubbing blah", failure.getException().getMessage());
}
@Test
public void shouldNotAppendWhenNoWarnings() throws Exception {
RuntimeException ex = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, ex);
//when
hacker.appendWarnings(failure, "");
//then
assertEquals(ex, failure.getException());
}
@Test
public void shouldNotAppendWhenNullWarnings() throws Exception {
RuntimeException ex = new RuntimeException("foo");
Failure failure = new Failure(Description.EMPTY, ex);
//when
hacker.appendWarnings(failure, null);
//then
assertEquals(ex, failure.getException());
}
@Test
public void shouldPrintTheWarningSoICanSeeIt() throws Exception {
Failure failure = new Failure(Description.EMPTY, new RuntimeException("foo"));
//when
hacker.appendWarnings(failure, "unused stubbing blah");
//then
System.out.println(failure.getException());
}
@Override
public Description getDescription() {
STEPS.add("description");
return Description.EMPTY;
}
@Override
public Description getDescription() {
return Description.EMPTY;
}