Skip to content

Commit 41b6529

Browse files
committed
Ensure default empty values are not enabled bby default
1 parent 099d9ea commit 41b6529

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

core/src/test/scala/org/mockito/ScalaDefaultAnswerTest.scala renamed to core/src/test/scala/org/mockito/DefaultAnswerTest.scala

+28-12
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package org.mockito
22

33
import org.scalatest
44
import org.mockito.exceptions.verification.SmartNullPointerException
5-
import org.mockito.ScalaDefaultAnswerTest._
5+
import org.mockito.DefaultAnswerTest._
66
import org.mockito.exceptions.base.MockitoException
77
import org.scalatest.{OptionValues, TryValues, WordSpec}
88
import org.scalatest.concurrent.ScalaFutures
99

1010
import scala.concurrent.Future
1111
import scala.util.{Success, Try}
1212

13-
object ScalaDefaultAnswerTest {
13+
object DefaultAnswerTest {
1414
class Foo {
1515
def bar(a: String) = "bar"
1616

@@ -19,6 +19,8 @@ object ScalaDefaultAnswerTest {
1919
def valueClass: ValueClass = ValueClass(42)
2020

2121
def userClass(v: Int = 42): Bar = new Bar
22+
23+
def returnsList: List[String] = List("not mocked!")
2224
}
2325

2426
case class ValueClass(v: Int) extends AnyVal
@@ -47,18 +49,18 @@ object ScalaDefaultAnswerTest {
4749
}
4850

4951
class Primitives {
50-
def barByte: Byte = 1.toByte
52+
def barByte: Byte = 1.toByte
5153
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
5860
}
5961
}
6062

61-
class ScalaDefaultAnswerTest
63+
class DefaultAnswerTest
6264
extends WordSpec
6365
with scalatest.Matchers
6466
with IdiomaticMockito
@@ -85,10 +87,24 @@ class ScalaDefaultAnswerTest
8587
}
8688

8789
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:
8991
|[foo.userClass(42);] on the Mock [$aMock]""".stripMargin
9092
}
9193

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+
92108
"return a default value for primitives" in {
93109
val primitives = mock[Primitives]
94110

@@ -107,7 +123,7 @@ class ScalaDefaultAnswerTest
107123
}
108124
}
109125

110-
"ReturnsEmptyValues" should {
126+
"ReturnsEmptyValues" should {
111127
"return the empty values for known classes" in {
112128
val aMock = mock[KnownTypes](ReturnsEmptyValues)
113129

0 commit comments

Comments
 (0)