Skip to content

Commit

Permalink
[TOREE-545] Upgrade Scalatest 3.2 and Mockito 4
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Aug 10, 2023
1 parent 0629402 commit 8f06fd3
Show file tree
Hide file tree
Showing 136 changed files with 782 additions and 586 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ ThisBuild / resolvers ++= Seq(
ThisBuild / updateOptions := updateOptions.value.withCachedResolution(true)
ThisBuild / libraryDependencies ++= Seq(
Dependencies.scalaTest % "test",
Dependencies.mockito % "test",
Dependencies.scalaTestMockito % "test",
Dependencies.mockitoInline % "test",
Dependencies.jacksonDatabind % "test"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ import org.apache.toree.kernel.protocol.v5.SocketType
import org.apache.toree.kernel.protocol.v5.socket._
import org.apache.toree.kernel.protocol.v5.socket.SocketConfig
import com.typesafe.config.ConfigFactory
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import scala.concurrent.duration._
class ClientToHeartbeatSpecForIntegration extends TestKit(ActorSystem("HeartbeatActorSpec"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
describe("HeartbeatActor") {
implicit val timeout = Timeout(1.minute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import org.apache.toree.kernel.protocol.v5._
import org.apache.toree.kernel.protocol.v5.content.ExecuteResult
import org.apache.toree.kernel.protocol.v5.socket._
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.Json
import scala.concurrent.duration._
class ClientToIOPubSpecForIntegration extends TestKit(ActorSystem("IOPubSystem"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
describe("Client-IOPub Integration"){
describe("Client"){
it("should connect to IOPub Socket"){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ import akka.zeromq._
import org.apache.toree.kernel.protocol.v5._
import org.apache.toree.kernel.protocol.v5.content.ExecuteRequest
import org.apache.toree.kernel.protocol.v5.socket._
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import play.api.libs.json.Json
class ClientToShellSpecForIntegration extends TestKit(ActorSystem("ShellActorSpec"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
describe("ShellActor") {
val clientSocketFactory = mock[ClientSocketFactory]
val serverSocketFactory = mock[ServerSocketFactory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import org.apache.toree.kernel.protocol.v5.client.ActorLoader
import org.apache.toree.kernel.protocol.v5.content.CommContent
import org.scalatestplus.mockito.MockitoSugar
import org.mockito.Mockito._
import org.mockito.Matchers._
import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
import org.mockito.ArgumentMatchers._
import org.scalatest.BeforeAndAfterEach
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers

class ClientCommManagerSpec extends FunSpec with Matchers with BeforeAndAfter
class ClientCommManagerSpec extends AnyFunSpec with Matchers with BeforeAndAfterEach
with MockitoSugar
{
private val TestTargetName = "some target"
Expand All @@ -38,7 +40,7 @@ class ClientCommManagerSpec extends FunSpec with Matchers with BeforeAndAfter

private var generatedCommWriter: CommWriter = _

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

generatedCommWriter = commWriter

val spyCommWriter = spy(commWriter)
val spyCommWriter = spy[CommWriter](commWriter)
doNothing().when(spyCommWriter)
.sendCommKernelMessage(any[KernelMessageContent with CommContent])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import org.apache.toree.kernel.protocol.v5._
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
import org.apache.toree.kernel.protocol.v5.content._
import com.typesafe.config.ConfigFactory
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfterEach
import play.api.libs.json.Json

import scala.concurrent.duration._
Expand All @@ -43,7 +45,7 @@ object ClientCommWriterSpec {
class ClientCommWriterSpec extends TestKit(
ActorSystem("ClientCommWriterSpec",
ConfigFactory.parseString(ClientCommWriterSpec.config))
) with FunSpecLike with Matchers with BeforeAndAfter with MockitoSugar
) with AnyFunSpecLike with Matchers with BeforeAndAfterEach with MockitoSugar
{

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

before {
kernelMessageBuilder = spy(KMBuilder())
override def beforeEach(): Unit = {
kernelMessageBuilder = spy[KMBuilder](KMBuilder())

// Construct path for kernel message relay
actorLoader = mock[ActorLoader]
shellSocketProbe = TestProbe()
val shellSocketSelection: ActorSelection =
system.actorSelection(shellSocketProbe.ref.path.toString)
doReturn(shellSocketSelection)
doReturn(shellSocketSelection, Nil: _*)
.when(actorLoader).load(SocketType.ShellClient)

// Create a new writer to use for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import org.apache.toree.kernel.protocol.v5._
import org.apache.toree.kernel.protocol.v5.client.execution.ExecuteRequestTuple
import scala.concurrent.duration._
import org.mockito.Mockito._
import org.mockito.Matchers.{eq => mockEq, _}
import org.mockito.ArgumentMatchers.{eq => mockEq, _}
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfterEach

class SparkKernelClientSpec
extends TestKit(ActorSystem("SparkKernelClientActorSystem"))
with Matchers with MockitoSugar with FunSpecLike with BeforeAndAfter
with Matchers with MockitoSugar with AnyFunSpecLike with BeforeAndAfterEach
{
private val TestTargetName = "some target"

Expand All @@ -41,7 +43,7 @@ class SparkKernelClientSpec
private var executeRequestProbe: TestProbe = _
private var shellClientProbe: TestProbe = _

before {
override def beforeEach(): Unit = {
mockActorLoader = mock[ActorLoader]
mockCommRegistrar = mock[CommRegistrar]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ package org.apache.toree.kernel.protocol.v5.client.execution
import org.apache.toree.kernel.protocol.v5.content.{StreamContent, ExecuteResult}
import org.apache.toree.kernel.protocol.v5.content._
import org.apache.toree.kernel.protocol.v5._
import org.scalatest.{Matchers, FunSpec}
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.concurrent.ScalaFutures

import scala.concurrent.Promise
Expand Down Expand Up @@ -64,7 +65,7 @@ object DeferredExecutionTest {
class ExecuteResultPromise {}
class ExecuteReplyPromise {}

class DeferredExecutionTest extends FunSpec with ScalaFutures with Matchers {
class DeferredExecutionTest extends AnyFunSpec with ScalaFutures with Matchers {
import DeferredExecutionTest._
describe("DeferredExecution") {
describe("onResult( callback )"){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import akka.testkit.{TestProbe, ImplicitSender, TestKit}
import org.apache.toree.communication.ZMQMessage
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{Matchers, FunSpecLike}
import org.mockito.Matchers._
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._

class HeartbeatClientSpec extends TestKit(ActorSystem("HeartbeatActorSpec"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {

describe("HeartbeatClientActor") {
val socketFactory = mock[SocketFactory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ import org.apache.toree.kernel.protocol.v5.client.execution.{DeferredExecution,
import org.apache.toree.kernel.protocol.v5.client.{ActorLoader, Utilities}
import org.apache.toree.kernel.protocol.v5.content.{CommClose, CommMsg, CommOpen, StreamContent}
import com.typesafe.config.ConfigFactory
import org.mockito.Matchers.{eq => mockEq, _}
import org.mockito.ArgumentMatchers.{eq => mockEq, _}
import org.mockito.Mockito._
import org.scalatest.concurrent.{Eventually, ScalaFutures}
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.time.{Milliseconds, Span}
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfterEach
import play.api.libs.json.Json

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

class IOPubClientSpec extends TestKit(ActorSystem(
"IOPubClientSpecSystem", ConfigFactory.parseString(IOPubClientSpec.config)
)) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
with ScalaFutures with BeforeAndAfter with Eventually
)) with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar
with ScalaFutures with BeforeAndAfterEach with Eventually
{
private val TestTimeout = Timeout(10.seconds)
implicit override val patienceConfig = PatienceConfig(
Expand All @@ -77,19 +79,19 @@ class IOPubClientSpec extends TestKit(ActorSystem(
private val TestTargetName = "some target"
private val TestCommId = UUID.randomUUID().toString

before {
override def beforeEach(): Unit = {
kmBuilder = KMBuilder()
mockCommCallbacks = mock[CommCallbacks]
mockCommRegistrar = mock[CommRegistrar]

spyCommStorage = spy(new CommStorage())
spyCommStorage = spy[CommStorage](new CommStorage())

clientSocketProbe = TestProbe()
mockActorLoader = mock[ActorLoader]
mockClientSocketFactory = mock[SocketFactory]

// Stub the return value for the socket factory
when(mockClientSocketFactory.IOPubClient(anyObject(), any[ActorRef]))
when(mockClientSocketFactory.IOPubClient(any[ActorSystem](), any[ActorRef]))
.thenReturn(clientSocketProbe.ref)

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

// Mark as target being provided
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
.getTargetCallbacks(anyString())

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

// Mark as target NOT being provided
doReturn(None).when(spyCommStorage).getTargetCallbacks(anyString())
doReturn(None, Nil: _*).when(spyCommStorage).getTargetCallbacks(anyString())

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

// Mark as target being provided
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
.getCommIdCallbacks(any[v5.UUID])

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

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

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

// Mark as target being provided
doReturn(Some(mockCommCallbacks)).when(spyCommStorage)
doReturn(Some(mockCommCallbacks), Nil: _*).when(spyCommStorage)
.getCommIdCallbacks(any[v5.UUID])

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

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

// Simulate receiving a message from the kernel
ioPubClient ! message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import org.apache.toree.kernel.protocol.v5._
import org.apache.toree.kernel.protocol.v5.client.ActorLoader
import org.apache.toree.kernel.protocol.v5.content.ExecuteRequest
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{Matchers, FunSpecLike}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.mockito.Mockito._
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._
import play.api.libs.json.Json

class ShellClientSpec extends TestKit(ActorSystem("ShellActorSpec"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar {
private val SignatureEnabled = true

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

val signatureManagerProbe = TestProbe()
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString))
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString), Nil: _*)
.when(mockActorLoader).load(SecurityActorType.SignatureManager)

val shellClient = system.actorOf(Props(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ import org.apache.toree.kernel.protocol.v5.client.ActorLoader
import org.apache.toree.kernel.protocol.v5.client.socket.StdinClient.{ResponseFunctionMessage, ResponseFunction}
import org.apache.toree.kernel.protocol.v5.content.{InputReply, InputRequest, ClearOutput, ExecuteRequest}
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfterEach
import org.apache.toree.kernel.protocol.v5.client.Utilities._
import play.api.libs.json.Json
import scala.concurrent.duration._

import org.mockito.Mockito._
import org.mockito.Matchers._
import org.mockito.ArgumentMatchers._

class StdinClientSpec extends TestKit(ActorSystem("StdinActorSpec"))
with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
with BeforeAndAfter
with ImplicitSender with AnyFunSpecLike with Matchers with MockitoSugar
with BeforeAndAfterEach
{
private val SignatureEnabled = true
private val TestReplyString = "some value"
Expand All @@ -48,14 +50,14 @@ class StdinClientSpec extends TestKit(ActorSystem("StdinActorSpec"))
private var socketProbe: TestProbe = _
private var stdinClient: ActorRef = _

before {
override def beforeEach(): Unit = {
socketProbe = TestProbe()
signatureManagerProbe = TestProbe()
mockSocketFactory = mock[SocketFactory]
mockActorLoader = mock[ActorLoader]
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString))
doReturn(system.actorSelection(signatureManagerProbe.ref.path.toString), Nil: _*)
.when(mockActorLoader).load(SecurityActorType.SignatureManager)
doReturn(socketProbe.ref).when(mockSocketFactory)
doReturn(socketProbe.ref, Nil: _*).when(mockSocketFactory)
.StdinClient(any[ActorSystem], any[ActorRef])

stdinClient = system.actorOf(Props(
Expand Down
Loading

0 comments on commit 8f06fd3

Please sign in to comment.