Skip to content

Commit b56f594

Browse files
committed
[TOREE-545] Upgrade Scalatest 3.2 and Mockito 4
1 parent 4634772 commit b56f594

File tree

135 files changed

+778
-587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+778
-587
lines changed

build.sbt

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ ThisBuild / resolvers ++= Seq(
7777
ThisBuild / updateOptions := updateOptions.value.withCachedResolution(true)
7878
ThisBuild / libraryDependencies ++= Seq(
7979
Dependencies.scalaTest % "test",
80-
Dependencies.mockito % "test",
80+
Dependencies.scalaTestMockito % "test",
81+
Dependencies.mockitoInline % "test",
8182
Dependencies.jacksonDatabind % "test"
8283
)
8384

client/src/test/scala/integration/unused.integration.socket/ClientToHeartbeatSpecForIntegration.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ import org.apache.toree.kernel.protocol.v5.SocketType
3131
import org.apache.toree.kernel.protocol.v5.socket._
3232
import org.apache.toree.kernel.protocol.v5.socket.SocketConfig
3333
import com.typesafe.config.ConfigFactory
34-
import org.mockito.Matchers._
34+
import org.mockito.ArgumentMatchers._
3535
import org.mockito.Mockito._
3636
import org.scalatestplus.mockito.MockitoSugar
37-
import org.scalatest.{FunSpecLike, Matchers}
37+
import org.scalatest.funspec.AnyFunSpecLike
38+
import org.scalatest.matchers.should.Matchers
3839
import scala.concurrent.duration._
3940
4041
4142
class ClientToHeartbeatSpecForIntegration extends TestKit(ActorSystem("HeartbeatActorSpec"))
42-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
43+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
4344
4445
describe("HeartbeatActor") {
4546
implicit val timeout = Timeout(1.minute)

client/src/test/scala/integration/unused.integration.socket/ClientToIOPubSpecForIntegration.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ import akka.testkit.{ImplicitSender, TestKit, TestProbe}
2727
import org.apache.toree.kernel.protocol.v5._
2828
import org.apache.toree.kernel.protocol.v5.content.ExecuteResult
2929
import org.apache.toree.kernel.protocol.v5.socket._
30-
import org.mockito.Matchers._
30+
import org.mockito.ArgumentMatchers._
3131
import org.mockito.Mockito._
3232
import org.scalatestplus.mockito.MockitoSugar
33-
import org.scalatest.{FunSpecLike, Matchers}
33+
import org.scalatest.funspec.AnyFunSpecLike
34+
import org.scalatest.matchers.should.Matchers
3435
import play.api.libs.json.Json
3536
3637
import scala.concurrent.duration._
3738
3839
class ClientToIOPubSpecForIntegration extends TestKit(ActorSystem("IOPubSystem"))
39-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
40+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
4041
describe("Client-IOPub Integration"){
4142
describe("Client"){
4243
it("should connect to IOPub Socket"){

client/src/test/scala/integration/unused.integration.socket/ClientToShellSpecForIntegration.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ import akka.zeromq._
2828
import org.apache.toree.kernel.protocol.v5._
2929
import org.apache.toree.kernel.protocol.v5.content.ExecuteRequest
3030
import org.apache.toree.kernel.protocol.v5.socket._
31-
import org.mockito.Matchers._
31+
import org.mockito.ArgumentMatchers._
3232
import org.mockito.Mockito._
3333
import org.scalatestplus.mockito.MockitoSugar
34-
import org.scalatest.{FunSpecLike, Matchers}
34+
import org.scalatest.funspec.AnyFunSpecLike
35+
import org.scalatest.matchers.should.Matchers
3536
import play.api.libs.json.Json
3637
3738
class ClientToShellSpecForIntegration extends TestKit(ActorSystem("ShellActorSpec"))
38-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
39+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
3940
describe("ShellActor") {
4041
val clientSocketFactory = mock[ClientSocketFactory]
4142
val serverSocketFactory = mock[ServerSocketFactory]

client/src/test/scala/org/apache/toree/comm/ClientCommManagerSpec.scala

+7-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ import org.apache.toree.kernel.protocol.v5.client.ActorLoader
2323
import org.apache.toree.kernel.protocol.v5.content.CommContent
2424
import org.scalatestplus.mockito.MockitoSugar
2525
import org.mockito.Mockito._
26-
import org.mockito.Matchers._
27-
import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
26+
import org.mockito.ArgumentMatchers._
27+
import org.scalatest.BeforeAndAfterEach
28+
import org.scalatest.funspec.AnyFunSpec
29+
import org.scalatest.matchers.should.Matchers
2830

29-
class ClientCommManagerSpec extends FunSpec with Matchers with BeforeAndAfter
31+
class ClientCommManagerSpec extends AnyFunSpec with Matchers with BeforeAndAfterEach
3032
with MockitoSugar
3133
{
3234
private val TestTargetName = "some target"
@@ -38,7 +40,7 @@ class ClientCommManagerSpec extends FunSpec with Matchers with BeforeAndAfter
3840

3941
private var generatedCommWriter: CommWriter = _
4042

41-
before {
43+
override def beforeEach(): Unit = {
4244
mockActorLoader = mock[ActorLoader]
4345
mockKMBuilder = mock[KMBuilder]
4446
mockCommRegistrar = mock[CommRegistrar]
@@ -53,7 +55,7 @@ class ClientCommManagerSpec extends FunSpec with Matchers with BeforeAndAfter
5355

5456
generatedCommWriter = commWriter
5557

56-
val spyCommWriter = spy(commWriter)
58+
val spyCommWriter = spy[CommWriter](commWriter)
5759
doNothing().when(spyCommWriter)
5860
.sendCommKernelMessage(any[KernelMessageContent with CommContent])
5961

client/src/test/scala/org/apache/toree/comm/ClientCommWriterSpec.scala

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import org.apache.toree.kernel.protocol.v5._
2525
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
2626
import org.apache.toree.kernel.protocol.v5.content._
2727
import com.typesafe.config.ConfigFactory
28-
import org.mockito.Matchers._
28+
import org.mockito.ArgumentMatchers._
2929
import org.mockito.Mockito._
3030
import org.scalatestplus.mockito.MockitoSugar
31-
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
31+
import org.scalatest.funspec.AnyFunSpecLike
32+
import org.scalatest.matchers.should.Matchers
33+
import org.scalatest.BeforeAndAfterEach
3234
import play.api.libs.json.Json
3335

3436
import scala.concurrent.duration._
@@ -43,7 +45,7 @@ object ClientCommWriterSpec {
4345
class ClientCommWriterSpec extends TestKit(
4446
ActorSystem("ClientCommWriterSpec",
4547
ConfigFactory.parseString(ClientCommWriterSpec.config))
46-
) with FunSpecLike with Matchers with BeforeAndAfter with MockitoSugar
48+
) with AnyFunSpecLike with Matchers with BeforeAndAfterEach with MockitoSugar
4749
{
4850

4951
private val commId = UUID.randomUUID().toString
@@ -84,15 +86,15 @@ class ClientCommWriterSpec extends TestKit(
8486
Json.parse(receivedMessage.contentString).as[T]
8587
}
8688

87-
before {
88-
kernelMessageBuilder = spy(KMBuilder())
89+
override def beforeEach(): Unit = {
90+
kernelMessageBuilder = spy[KMBuilder](KMBuilder())
8991

9092
// Construct path for kernel message relay
9193
actorLoader = mock[ActorLoader]
9294
shellSocketProbe = TestProbe()
9395
val shellSocketSelection: ActorSelection =
9496
system.actorSelection(shellSocketProbe.ref.path.toString)
95-
doReturn(shellSocketSelection)
97+
doReturn(shellSocketSelection, Nil: _*)
9698
.when(actorLoader).load(SocketType.ShellClient)
9799

98100
// Create a new writer to use for testing

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/SparkKernelClientSpec.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ import org.apache.toree.kernel.protocol.v5._
2525
import org.apache.toree.kernel.protocol.v5.client.execution.ExecuteRequestTuple
2626
import scala.concurrent.duration._
2727
import org.mockito.Mockito._
28-
import org.mockito.Matchers.{eq => mockEq, _}
28+
import org.mockito.ArgumentMatchers.{eq => mockEq, _}
2929
import org.scalatestplus.mockito.MockitoSugar
30-
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
30+
import org.scalatest.funspec.AnyFunSpecLike
31+
import org.scalatest.matchers.should.Matchers
32+
import org.scalatest.BeforeAndAfterEach
3133

3234
class SparkKernelClientSpec
3335
extends TestKit(ActorSystem("SparkKernelClientActorSystem"))
34-
with Matchers with MockitoSugar with FunSpecLike with BeforeAndAfter
36+
with Matchers with MockitoSugar with AnyFunSpecLike with BeforeAndAfterEach
3537
{
3638
private val TestTargetName = "some target"
3739

@@ -41,7 +43,7 @@ class SparkKernelClientSpec
4143
private var executeRequestProbe: TestProbe = _
4244
private var shellClientProbe: TestProbe = _
4345

44-
before {
46+
override def beforeEach(): Unit = {
4547
mockActorLoader = mock[ActorLoader]
4648
mockCommRegistrar = mock[CommRegistrar]
4749

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/execution/DeferredExecutionTest.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ package org.apache.toree.kernel.protocol.v5.client.execution
2020
import org.apache.toree.kernel.protocol.v5.content.{StreamContent, ExecuteResult}
2121
import org.apache.toree.kernel.protocol.v5.content._
2222
import org.apache.toree.kernel.protocol.v5._
23-
import org.scalatest.{Matchers, FunSpec}
23+
import org.scalatest.funspec.AnyFunSpec
24+
import org.scalatest.matchers.should.Matchers
2425
import org.scalatest.concurrent.ScalaFutures
2526

2627
import scala.concurrent.Promise
@@ -64,7 +65,7 @@ object DeferredExecutionTest {
6465
class ExecuteResultPromise {}
6566
class ExecuteReplyPromise {}
6667

67-
class DeferredExecutionTest extends FunSpec with ScalaFutures with Matchers {
68+
class DeferredExecutionTest extends AnyFunSpec with ScalaFutures with Matchers {
6869
import DeferredExecutionTest._
6970
describe("DeferredExecution") {
7071
describe("onResult( callback )"){

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/socket/HeartbeatClientSpec.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ import akka.testkit.{TestProbe, ImplicitSender, TestKit}
2222
import org.apache.toree.communication.ZMQMessage
2323
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
2424
import org.scalatestplus.mockito.MockitoSugar
25-
import org.scalatest.{Matchers, FunSpecLike}
26-
import org.mockito.Matchers._
25+
import org.scalatest.funspec.AnyFunSpecLike
26+
import org.scalatest.matchers.should.Matchers
27+
import org.mockito.ArgumentMatchers._
2728
import org.mockito.Mockito._
2829

2930
class HeartbeatClientSpec extends TestKit(ActorSystem("HeartbeatActorSpec"))
30-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
31+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
3132

3233
describe("HeartbeatClientActor") {
3334
val socketFactory = mock[SocketFactory]

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/socket/IOPubClientSpec.scala

+15-13
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ import org.apache.toree.kernel.protocol.v5.client.execution.{DeferredExecution,
3232
import org.apache.toree.kernel.protocol.v5.client.{ActorLoader, Utilities}
3333
import org.apache.toree.kernel.protocol.v5.content.{CommClose, CommMsg, CommOpen, StreamContent}
3434
import com.typesafe.config.ConfigFactory
35-
import org.mockito.Matchers.{eq => mockEq, _}
35+
import org.mockito.ArgumentMatchers.{eq => mockEq, _}
3636
import org.mockito.Mockito._
3737
import org.scalatest.concurrent.{Eventually, ScalaFutures}
3838
import org.scalatestplus.mockito.MockitoSugar
3939
import org.scalatest.time.{Milliseconds, Span}
40-
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
40+
import org.scalatest.funspec.AnyFunSpecLike
41+
import org.scalatest.matchers.should.Matchers
42+
import org.scalatest.BeforeAndAfterEach
4143
import play.api.libs.json.Json
4244

4345
import scala.concurrent.duration._
@@ -53,8 +55,8 @@ object IOPubClientSpec {
5355

5456
class IOPubClientSpec extends TestKit(ActorSystem(
5557
"IOPubClientSpecSystem", ConfigFactory.parseString(IOPubClientSpec.config)
56-
)) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
57-
with ScalaFutures with BeforeAndAfter with Eventually
58+
)) with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar
59+
with ScalaFutures with BeforeAndAfterEach with Eventually
5860
{
5961
private val TestTimeout = Timeout(10.seconds)
6062
implicit override val patienceConfig = PatienceConfig(
@@ -77,19 +79,19 @@ class IOPubClientSpec extends TestKit(ActorSystem(
7779
private val TestTargetName = "some target"
7880
private val TestCommId = UUID.randomUUID().toString
7981

80-
before {
82+
override def beforeEach(): Unit = {
8183
kmBuilder = KMBuilder()
8284
mockCommCallbacks = mock[CommCallbacks]
8385
mockCommRegistrar = mock[CommRegistrar]
8486

85-
spyCommStorage = spy(new CommStorage())
87+
spyCommStorage = spy[CommStorage](new CommStorage())
8688

8789
clientSocketProbe = TestProbe()
8890
mockActorLoader = mock[ActorLoader]
8991
mockClientSocketFactory = mock[SocketFactory]
9092

9193
// Stub the return value for the socket factory
92-
when(mockClientSocketFactory.IOPubClient(anyObject(), any[ActorRef]))
94+
when(mockClientSocketFactory.IOPubClient(any[ActorSystem](), any[ActorRef]))
9395
.thenReturn(clientSocketProbe.ref)
9496

9597
// Construct the object we will test against
@@ -108,7 +110,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
108110
.build
109111

110112
// Mark as target being provided
111-
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
113+
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
112114
.getTargetCallbacks(anyString())
113115

114116
// Simulate receiving a message from the kernel
@@ -129,7 +131,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
129131
.build
130132

131133
// Mark as target NOT being provided
132-
doReturn(None).when(spyCommStorage).getTargetCallbacks(anyString())
134+
doReturn(None, Nil: _*).when(spyCommStorage).getTargetCallbacks(anyString())
133135

134136
// Simulate receiving a message from the kernel
135137
ioPubClient ! message
@@ -153,7 +155,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
153155
.build
154156

155157
// Mark as target being provided
156-
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
158+
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
157159
.getCommIdCallbacks(any[v5.UUID])
158160

159161
// Simulate receiving a message from the kernel
@@ -173,7 +175,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
173175
.build
174176

175177
// Mark as target NOT being provided
176-
doReturn(None).when(spyCommStorage).getCommIdCallbacks(any[v5.UUID])
178+
doReturn(None, Nil: _*).when(spyCommStorage).getCommIdCallbacks(any[v5.UUID])
177179

178180
// Simulate receiving a message from the kernel
179181
ioPubClient ! message
@@ -195,7 +197,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
195197
.build
196198

197199
// Mark as target being provided
198-
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
200+
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
199201
.getCommIdCallbacks(any[v5.UUID])
200202

201203
// Simulate receiving a message from the kernel
@@ -215,7 +217,7 @@ class IOPubClientSpec extends TestKit(ActorSystem(
215217
.build
216218

217219
// Mark as target NOT being provided
218-
doReturn(None).when(spyCommStorage).getCommIdCallbacks(any[v5.UUID])
220+
doReturn(None, Nil: _*).when(spyCommStorage).getCommIdCallbacks(any[v5.UUID])
219221

220222
// Simulate receiving a message from the kernel
221223
ioPubClient ! message

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/socket/ShellClientSpec.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import org.apache.toree.kernel.protocol.v5._
2727
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
2828
import org.apache.toree.kernel.protocol.v5.content.ExecuteRequest
2929
import org.scalatestplus.mockito.MockitoSugar
30-
import org.scalatest.{Matchers, FunSpecLike}
30+
import org.scalatest.funspec.AnyFunSpecLike
31+
import org.scalatest.matchers.should.Matchers
3132
import org.mockito.Mockito._
32-
import org.mockito.Matchers._
33+
import org.mockito.ArgumentMatchers._
3334
import play.api.libs.json.Json
3435

3536
class ShellClientSpec extends TestKit(ActorSystem("ShellActorSpec"))
36-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
37+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
3738
private val SignatureEnabled = true
3839

3940
describe("ShellClientActor") {
@@ -45,7 +46,7 @@ class ShellClientSpec extends TestKit(ActorSystem("ShellActorSpec"))
4546
)).thenReturn(probe.ref)
4647

4748
val signatureManagerProbe = TestProbe()
48-
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString))
49+
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString), Nil: _*)
4950
.when(mockActorLoader).load(SecurityActorType.SignatureManager)
5051

5152
val shellClient = system.actorOf(Props(

client/src/test/scala/org/apache/toree/kernel/protocol/v5/client/socket/StdinClientSpec.scala

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ import org.apache.toree.kernel.protocol.v5.client.ActorLoader
2626
import org.apache.toree.kernel.protocol.v5.client.socket.StdinClient.{ResponseFunctionMessage, ResponseFunction}
2727
import org.apache.toree.kernel.protocol.v5.content.{InputReply, InputRequest, ClearOutput, ExecuteRequest}
2828
import org.scalatestplus.mockito.MockitoSugar
29-
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
29+
import org.scalatest.funspec.AnyFunSpecLike
30+
import org.scalatest.matchers.should.Matchers
31+
import org.scalatest.BeforeAndAfterEach
3032
import org.apache.toree.kernel.protocol.v5.client.Utilities._
3133
import play.api.libs.json.Json
3234
import scala.concurrent.duration._
3335

3436
import org.mockito.Mockito._
35-
import org.mockito.Matchers._
37+
import org.mockito.ArgumentMatchers._
3638

3739
class StdinClientSpec extends TestKit(ActorSystem("StdinActorSpec"))
38-
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
39-
with BeforeAndAfter
40+
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar
41+
with BeforeAndAfterEach
4042
{
4143
private val SignatureEnabled = true
4244
private val TestReplyString = "some value"
@@ -48,14 +50,14 @@ class StdinClientSpec extends TestKit(ActorSystem("StdinActorSpec"))
4850
private var socketProbe: TestProbe = _
4951
private var stdinClient: ActorRef = _
5052

51-
before {
53+
override def beforeEach(): Unit = {
5254
socketProbe = TestProbe()
5355
signatureManagerProbe = TestProbe()
5456
mockSocketFactory = mock[SocketFactory]
5557
mockActorLoader = mock[ActorLoader]
56-
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString))
58+
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString), Nil: _*)
5759
.when(mockActorLoader).load(SecurityActorType.SignatureManager)
58-
doReturn(socketProbe.ref).when(mockSocketFactory)
60+
doReturn(socketProbe.ref, Nil: _*).when(mockSocketFactory)
5961
.StdinClient(any[ActorSystem], any[ActorRef])
6062

6163
stdinClient = system.actorOf(Props(

0 commit comments

Comments
 (0)