Skip to content

Commit

Permalink
bump: ScalaTest 2.3.15 (was 2.3.11) + drop ScalaTest+ Mockito (#2976)
Browse files Browse the repository at this point in the history
* bump: ScalaTest 2.3.15 (was 2.3.11) + drop ScalaTest+ Mockito
* mongodb: make PatienceConfig apply in beforeAll
* Cassandra: try not to mislead with a NPE
  • Loading branch information
ennru authored May 4, 2023
1 parent 00cf4cc commit ed36576
Show file tree
Hide file tree
Showing 25 changed files with 117 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ package akka.stream.alpakka.amqp.scaladsl

import com.rabbitmq.client.{Address, Channel, ConfirmCallback, ConfirmListener, Connection, ConnectionFactory}
import org.mockito.ArgumentMatchers._
import org.scalatestplus.mockito.MockitoSugar
import org.mockito.Mockito.mock
import org.mockito.Mockito.when

trait AmqpMocking extends MockitoSugar {
trait AmqpMocking {

val channelMock: Channel = mock[Channel]
val channelMock: Channel = mock(classOf[Channel])

val connectionMock: Connection = mock[Connection]
val connectionMock: Connection = mock(classOf[Connection])

def connectionFactoryMock: ConnectionFactory = {
val connectionFactory = mock[ConnectionFactory]
val connectionFactory = mock(classOf[ConnectionFactory])

when(connectionFactory.newConnection(any[java.util.List[Address]]))
.thenReturn(connectionMock)
Expand All @@ -25,7 +25,7 @@ trait AmqpMocking extends MockitoSugar {
.thenReturn(channelMock)

when(channelMock.addConfirmListener(any[ConfirmCallback](), any[ConfirmCallback]()))
.thenReturn(mock[ConfirmListener])
.thenReturn(mock(classOf[ConfirmListener]))

connectionFactory
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ package akka.stream.alpakka.aws.eventbridge

import akka.actor.ActorSystem
import org.mockito.Mockito.reset
import org.mockito.Mockito.mock
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import org.scalatestplus.mockito.MockitoSugar
import software.amazon.awssdk.services.eventbridge.EventBridgeAsyncClient

import scala.concurrent.Await
import scala.concurrent.duration._

trait DefaultTestContext extends BeforeAndAfterAll with BeforeAndAfterEach with MockitoSugar { this: Suite =>
trait DefaultTestContext extends BeforeAndAfterAll with BeforeAndAfterEach { this: Suite =>

implicit protected val system: ActorSystem = ActorSystem()
implicit protected val eventBridgeClient: EventBridgeAsyncClient = mock[EventBridgeAsyncClient]
implicit protected val eventBridgeClient: EventBridgeAsyncClient = mock(classOf[EventBridgeAsyncClient])

override protected def beforeEach(): Unit =
reset(eventBridgeClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatestplus.mockito.MockitoSugar
import software.amazon.awssdk.core.SdkBytes
import software.amazon.awssdk.services.lambda.LambdaAsyncClient
import software.amazon.awssdk.services.lambda.model.{InvokeRequest, InvokeResponse}
Expand All @@ -36,12 +35,11 @@ class AwsLambdaFlowSpec
with BeforeAndAfterEach
with ScalaFutures
with Matchers
with MockitoSugar
with LogCapturing {

implicit val ec = system.dispatcher

implicit val awsLambdaClient = mock[LambdaAsyncClient]
implicit val awsLambdaClient = mock(classOf[LambdaAsyncClient])

override protected def afterEach(): Unit = {
reset(awsLambdaClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void beforeAll() {

@AfterClass
public static void afterAll() {
helper.shutdown();
if (helper != null) helper.shutdown();
}

ActorSystem system = helper.system;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static <T> T await(CompletionStage<T> cs)
}

public static <T> T await(Future<T> future) {
int seconds = 10;
int seconds = 15;
try {
return Await.result(future, FiniteDuration.create(seconds, TimeUnit.SECONDS));
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import akka.stream.alpakka.googlecloud.bigquery.storage.scaladsl.{
BigQueryStorageAttributes,
GrpcBigQueryStorageReader
}
import org.scalatestplus.mockito.MockitoSugar.mock
import org.mockito.Mockito.mock

//#read-all
import akka.NotUsed
Expand Down Expand Up @@ -45,7 +45,7 @@ class ExampleReader {

//#read-merged
implicit val unmarshaller: FromByteStringUnmarshaller[List[BigQueryRecord]] =
mock[FromByteStringUnmarshaller[List[BigQueryRecord]]]
mock(classOf[FromByteStringUnmarshaller[List[BigQueryRecord]]])
val sequentialSource: Source[List[BigQueryRecord], Future[NotUsed]] =
BigQueryStorage.createMergedStreams("projectId", "datasetId", "tableId", DataFormat.AVRO)
//#read-merged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar

import scala.collection.immutable.Seq
import scala.concurrent.duration._

class GooglePubSubSpec
extends AnyFlatSpec
with MockitoSugar
with ScalaFutures
with Matchers
with LogCapturing
with BeforeAndAfterAll {
class GooglePubSubSpec extends AnyFlatSpec with ScalaFutures with Matchers with LogCapturing with BeforeAndAfterAll {

implicit val defaultPatience =
PatienceConfig(timeout = 5.seconds, interval = 100.millis)
Expand All @@ -42,7 +35,7 @@ class GooglePubSubSpec
}

private trait Fixtures {
lazy val mockHttpApi = mock[PubSubApi]
lazy val mockHttpApi = mock(classOf[PubSubApi])
lazy val googlePubSub = new GooglePubSub {
override val httpApi = mockHttpApi
}
Expand All @@ -52,7 +45,7 @@ class GooglePubSubSpec
def tokenFlow[T]: Flow[T, (T, Option[String]), NotUsed] =
Flow[T].map(request => (request, Some("ok")))

val http: HttpExt = mock[HttpExt]
val http: HttpExt = mock(classOf[HttpExt])
val config = PubSubConfig()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import akka.stream.alpakka.google.{GoogleHttpException, GoogleSettings, RequestS
import akka.stream.scaladsl.{Flow, Keep, Sink, Source}
import akka.testkit.TestKit
import org.mockito.ArgumentMatchers.{any, anyInt, argThat}
import org.mockito.Mockito.when
import org.mockito.Mockito.{mock, when}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatestplus.mockito.MockitoSugar
import spray.json.{JsObject, JsValue}

import scala.annotation.nowarn
Expand All @@ -38,13 +37,12 @@ class GoogleHttpSpec
with AnyWordSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures
with MockitoSugar {
with ScalaFutures {

override def afterAll(): Unit = TestKit.shutdownActorSystem(system)

def mockHttp: HttpExt = {
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(http.system) thenReturn system.asInstanceOf[ExtendedActorSystem]
http
}
Expand All @@ -62,8 +60,8 @@ class GoogleHttpSpec
).thenReturn(Flow[Any]
.zipWith(response)(Keep.right)
.map(Try(_))
.map((_, mock[Nothing]))
.mapMaterializedValue(_ => mock[HostConnectionPool]),
.map((_, mock(classOf[Nothing])))
.mapMaterializedValue(_ => mock(classOf[HostConnectionPool])),
Nil: _*): @nowarn("msg=dead code")
http
}
Expand Down Expand Up @@ -157,7 +155,7 @@ class GoogleHttpSpec

final class AnotherException extends RuntimeException

val credentials = mock[Credentials]
val credentials = mock(classOf[Credentials])
when(credentials.get()(any[ExecutionContext], any[RequestSettings])).thenReturn(
Future.failed(GoogleOAuth2Exception(ErrorInfo())),
Future.failed(new AnotherException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.testkit.TestKit
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.{doReturn, verify, when}
import org.mockito.Mockito.{doReturn, mock, verify, when}
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.mockito.MockitoSugar
import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.matchers.should.Matchers
Expand All @@ -33,7 +32,6 @@ class FcmSenderSpec
with AnyWordSpecLike
with Matchers
with ScalaFutures
with MockitoSugar
with BeforeAndAfterAll
with LogCapturing {

Expand All @@ -54,7 +52,7 @@ class FcmSenderSpec

"call the api as the docs want to" in {
val sender = new FcmSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand All @@ -81,7 +79,7 @@ class FcmSenderSpec

"parse the success response correctly" in {
val sender = new FcmSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand All @@ -99,7 +97,7 @@ class FcmSenderSpec

"parse the error response correctly" in {
val sender = new FcmSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.testkit.TestKit
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.{verify, when}
import org.mockito.Mockito.{mock, verify, when}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatestplus.mockito.MockitoSugar

import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration.DurationInt
Expand All @@ -31,7 +30,6 @@ class HmsTokenApiSpec
with AnyWordSpecLike
with Matchers
with ScalaFutures
with MockitoSugar
with BeforeAndAfterAll
with LogCapturing {

Expand All @@ -49,7 +47,7 @@ class HmsTokenApiSpec

"call the api as the docs want to" in {

val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand Down Expand Up @@ -82,7 +80,7 @@ class HmsTokenApiSpec
}

"return the token" in {
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import akka.stream.alpakka.testkit.scaladsl.LogCapturing
import akka.testkit.TestKit
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.{verify, when}
import org.mockito.Mockito.{mock, verify, when}
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatestplus.mockito.MockitoSugar

import scala.concurrent.{Await, ExecutionContext, Future}

Expand All @@ -31,7 +30,6 @@ class PushKitSenderSpec
with AnyWordSpecLike
with Matchers
with ScalaFutures
with MockitoSugar
with BeforeAndAfterAll
with LogCapturing {

Expand All @@ -51,7 +49,7 @@ class PushKitSenderSpec

"call the api as the docs want to" in {
val sender = new PushKitSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand Down Expand Up @@ -83,7 +81,7 @@ class PushKitSenderSpec

"parse the success response correctly" in {
val sender = new PushKitSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand All @@ -105,7 +103,7 @@ class PushKitSenderSpec

"parse the error response correctly" in {
val sender = new PushKitSender
val http = mock[HttpExt]
val http = mock(classOf[HttpExt])
when(
http.singleRequest(any[HttpRequest](),
any[HttpsConnectionContext](),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import akka.stream.alpakka.jms.scaladsl.{JmsConsumer, JmsProducer}
import akka.stream.scaladsl.{Keep, Sink, Source}
import javax.jms.{JMSException, Message, TextMessage}
import org.mockito.ArgumentMatchers.{any, anyInt, anyLong}
import org.mockito.Mockito.when
import org.mockito.Mockito.{mock, when}
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer

Expand Down Expand Up @@ -173,7 +173,7 @@ class JmsProducerRetrySpec extends JmsSpec {
"retry send as often as configured" in withMockedProducer { ctx =>
import ctx._
val sendAttempts = new AtomicInteger()
val message = mock[TextMessage]
val message = mock(classOf[TextMessage])

when(session.createTextMessage(any[String])).thenReturn(message)

Expand Down Expand Up @@ -202,7 +202,7 @@ class JmsProducerRetrySpec extends JmsSpec {
"fail send on first attempt if retry is disabled" in withMockedProducer { ctx =>
import ctx._
val sendAttempts = new AtomicInteger()
val message = mock[TextMessage]
val message = mock(classOf[TextMessage])

when(session.createTextMessage(any[String])).thenReturn(message)

Expand Down
Loading

0 comments on commit ed36576

Please sign in to comment.