@@ -2,15 +2,15 @@ package org.mockito
2
2
3
3
import org .scalatest
4
4
import org .mockito .exceptions .verification .SmartNullPointerException
5
- import org .mockito .ScalaDefaultAnswerTest ._
5
+ import org .mockito .DefaultAnswerTest ._
6
6
import org .mockito .exceptions .base .MockitoException
7
7
import org .scalatest .{OptionValues , TryValues , WordSpec }
8
8
import org .scalatest .concurrent .ScalaFutures
9
9
10
10
import scala .concurrent .Future
11
11
import scala .util .{Success , Try }
12
12
13
- object ScalaDefaultAnswerTest {
13
+ object DefaultAnswerTest {
14
14
class Foo {
15
15
def bar (a : String ) = " bar"
16
16
@@ -19,6 +19,8 @@ object ScalaDefaultAnswerTest {
19
19
def valueClass : ValueClass = ValueClass (42 )
20
20
21
21
def userClass (v : Int = 42 ): Bar = new Bar
22
+
23
+ def returnsList : List [String ] = List (" not mocked!" )
22
24
}
23
25
24
26
case class ValueClass (v : Int ) extends AnyVal
@@ -47,18 +49,18 @@ object ScalaDefaultAnswerTest {
47
49
}
48
50
49
51
class Primitives {
50
- def barByte : Byte = 1 .toByte
52
+ def barByte : Byte = 1 .toByte
51
53
def barBoolean : Boolean = true
52
- def barChar : Char = '1'
53
- def barDouble : Double = 1
54
- def barInt : Int = 1
55
- def barFloat : Float = 1
56
- def barShort : Short = 1
57
- def barLong : Long = 1
54
+ def barChar : Char = '1'
55
+ def barDouble : Double = 1
56
+ def barInt : Int = 1
57
+ def barFloat : Float = 1
58
+ def barShort : Short = 1
59
+ def barLong : Long = 1
58
60
}
59
61
}
60
62
61
- class ScalaDefaultAnswerTest
63
+ class DefaultAnswerTest
62
64
extends WordSpec
63
65
with scalatest.Matchers
64
66
with IdiomaticMockito
@@ -85,10 +87,24 @@ class ScalaDefaultAnswerTest
85
87
}
86
88
87
89
throwable.getMessage shouldBe
88
- s """ You have a NullPointerException because this method call was *not* stubbed correctly:
90
+ s """ You have a NullPointerException because this method call was *not* stubbed correctly:
89
91
|[foo.userClass(42);] on the Mock [ $aMock] """ .stripMargin
90
92
}
91
93
94
+ " return a smart standard monads" in {
95
+ val smartNull : List [String ] = aMock.returnsList
96
+
97
+ smartNull should not be null
98
+
99
+ val throwable : SmartNullPointerException = the[SmartNullPointerException ] thrownBy {
100
+ smartNull.isEmpty
101
+ }
102
+
103
+ throwable.getMessage shouldBe
104
+ s """ You have a NullPointerException because this method call was *not* stubbed correctly:
105
+ |[foo.returnsList();] on the Mock [ $aMock] """ .stripMargin
106
+ }
107
+
92
108
" return a default value for primitives" in {
93
109
val primitives = mock[Primitives ]
94
110
@@ -107,7 +123,7 @@ class ScalaDefaultAnswerTest
107
123
}
108
124
}
109
125
110
- " ReturnsEmptyValues" should {
126
+ " ReturnsEmptyValues" should {
111
127
" return the empty values for known classes" in {
112
128
val aMock = mock[KnownTypes ](ReturnsEmptyValues )
113
129
0 commit comments