1
1
package org .mockito .scalatest
2
+
2
3
import org .mockito .{ MockitoScalaSession , Strictness }
3
4
import org .scalatest ._
4
5
5
- import scala .util .control .NonFatal
6
-
7
6
private [mockito] trait MockitoSessionFixture extends TestSuite { this : Suite =>
8
7
9
8
val strictness : Strictness = Strictness .StrictStubs
10
9
11
10
abstract override def withFixture (test : NoArgTest ): Outcome = {
12
11
val session = MockitoScalaSession (name = s " ${test.name} - session " , strictness)
13
- val result = super .withFixture(test)
14
- // if the test has thrown an exception, the session will check first if the exception could be related to a mis-use
15
- // of mockito, if not, it will throw nothing so the real test failure can be reported by the ScalaTest
12
+
13
+ val result =
14
+ try {
15
+ super .withFixture(test)
16
+ } catch {
17
+ case t : Throwable =>
18
+ session.finishMocking(Some (t))
19
+ throw t
20
+ }
21
+
16
22
session.finishMocking(result.toOption)
17
23
result
18
24
}
@@ -25,15 +31,13 @@ private[mockito] trait MockitoSessionAsyncFixture extends AsyncTestSuite { this:
25
31
abstract override def withFixture (test : NoArgAsyncTest ): FutureOutcome = {
26
32
val session = MockitoScalaSession (name = s " ${test.name} - session " , strictness)
27
33
28
- // if the test has thrown an exception, the session will check first if the exception could be related to a mis-use
29
- // of mockito, if not, it will throw nothing so the real test failure can be reported by the ScalaTest
30
34
val result =
31
35
try {
32
36
super .withFixture(test)
33
37
} catch {
34
- case NonFatal (ex) =>
35
- session.finishMocking(Some (ex ))
36
- throw ex
38
+ case t : Throwable =>
39
+ session.finishMocking(Some (t ))
40
+ throw t
37
41
}
38
42
39
43
result.onOutcomeThen(o => session.finishMocking(o.toOption))
0 commit comments