Skip to content

Commit b343344

Browse files
committed
Merge branch 'feature/assumption-failure' of https://github.com/retronym/scalatestplus-junit
2 parents a340d32 + 11accfe commit b343344

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

src/main/scala/org/scalatestplus/junit/RunNotifierReporter.scala

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ private[junit] class RunNotifierReporter(runNotifier: RunNotifier) extends Repor
6161
runNotifier.fireTestStarted(Description.createSuiteDescription(testDescriptionName(suiteName, suiteClassName, testName)))
6262

6363
case TestFailed(ordinal, message, suiteName, suiteId, suiteClassName, testName, testText, recordedEvents, analysis, throwable, duration, formatter, location, rerunnable, payload, threadName, timeStamp) =>
64-
val throwableOrNull =
65-
throwable match {
66-
case Some(t) => t
67-
case None => null // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
68-
}
64+
val throwableOrNull = throwable.orNull // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
6965
val description = Description.createSuiteDescription(testDescriptionName(suiteName, suiteClassName, testName))
7066
runNotifier.fireTestFailure(new Failure(description, throwableOrNull))
7167
runNotifier.fireTestFinished(description)
@@ -76,27 +72,23 @@ private[junit] class RunNotifierReporter(runNotifier: RunNotifier) extends Repor
7672
case TestIgnored(ordinal, suiteName, suiteId, suiteClassName, testName, testText, formatter, location, payload, threadName, timeStamp) =>
7773
runNotifier.fireTestIgnored(Description.createSuiteDescription(testDescriptionName(suiteName, suiteClassName, testName)))
7874

79-
// TODO: I dont see TestCanceled here. Probably need to add it
80-
// Closest thing we can do with pending is report an ignored test
75+
case TestCanceled(ordering, message, suiteName, suiteId, suiteClassName, testName, testText, recordedEvents, throwable, duration, formatter, location, rerunner, payload, threadName, timeStamp) =>
76+
val throwableOrNull = throwable.orNull // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
77+
val description = Description.createSuiteDescription(testDescriptionName(suiteName, suiteClassName, testName))
78+
runNotifier.fireTestAssumptionFailed(new Failure(description, throwableOrNull))
79+
runNotifier.fireTestFinished(description)
80+
8181
case TestPending(ordinal, suiteName, suiteId, suiteClassName, testName, testText, recordedEvents, duration, formatter, location, payload, threadName, timeStamp) =>
8282
runNotifier.fireTestIgnored(Description.createSuiteDescription(testDescriptionName(suiteName, suiteClassName, testName)))
8383

84-
case SuiteAborted(ordinal, message, suiteName, suiteId, suiteClassName, throwable, duration, formatter, location, rerunnable, payload, threadName, timeStamp) =>
85-
val throwableOrNull =
86-
throwable match {
87-
case Some(t) => t
88-
case None => null // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
89-
}
84+
case SuiteAborted(ordinal, message, suiteName, suiteId, suiteClassName, throwable, duration, formatter, location, rerunnable, payload, threadName, timeStamp) =>
85+
val throwableOrNull = throwable.orNull // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
9086
val description = Description.createSuiteDescription(suiteDescriptionName(suiteName, suiteClassName))
9187
runNotifier.fireTestFailure(new Failure(description, throwableOrNull)) // Best we can do in JUnit, as far as I know
9288
runNotifier.fireTestFinished(description)
9389

94-
case RunAborted(ordinal, message, throwable, duration, summary, formatter, location, payload, threadName, timeStamp) =>
95-
val throwableOrNull =
96-
throwable match {
97-
case Some(t) => t
98-
case None => null // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
99-
}
90+
case RunAborted(ordinal, message, throwable, duration, summary, formatter, location, payload, threadName, timeStamp) =>
91+
val throwableOrNull = throwable.orNull // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
10092
val possiblyEmptyMessage = messageOrThrowablesDetailMessage(message, throwable)
10193
val description = Description.createSuiteDescription(Resources.runAborted() + " " + possiblyEmptyMessage)
10294
runNotifier.fireTestFailure(new Failure(description, throwableOrNull)) // Best we can do in JUnit, as far as I know

src/test/java/org/scalatestplus/junit/JUnit3TestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.scalatestplus.junit;
1717

1818
import junit.framework.TestCase;
19+
import org.junit.Assume;
1920

2021
public class JUnit3TestCase extends TestCase {
2122

src/test/scala/org/scalatestplus/junit/RunNotifierSuite.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
8080
assert(runNotifier.passed.get.getDescription.getDisplayName === "theTestName(SuiteClassName)")
8181
}
8282

83+
test("report(TestCanceled) generates a fireTestAssumptionFailed invocation") {
84+
class MyRunNotifier extends RunNotifier {
85+
var methodInvocationCount = 0
86+
var passed: Option[Failure] = None
87+
88+
override def fireTestAssumptionFailed(failure: Failure): Unit = {
89+
methodInvocationCount += 1
90+
passed = Some(failure)
91+
}
92+
}
93+
val runNotifier = new MyRunNotifier
94+
95+
val reporter = new RunNotifierReporter(runNotifier)
96+
val exception = new IllegalArgumentException
97+
98+
import scala.language.reflectiveCalls
99+
100+
reporter(TestCanceled(ordinal, "No msg", "SuiteClassName", "suite ID", Some("fully.qualified.SuiteClassName"), "theTestName", "theTestName", Vector.empty, Some(exception)))
101+
assert(runNotifier.passed.get.getDescription.getDisplayName === "theTestName(fully.qualified.SuiteClassName)")
102+
reporter(TestCanceled(ordinal, "No msg", "SuiteClassName", "suite ID", None, "theTestName", "theTestName", Vector.empty, Some(exception)))
103+
assert(runNotifier.passed.get.getDescription.getDisplayName === "theTestName(SuiteClassName)")
104+
}
105+
83106
test("report(TestSucceeded) generates a fireTestFinished invocation") {
84107
class MyRunNotifier extends RunNotifier {
85108
var methodInvocationCount = 0

0 commit comments

Comments
 (0)