From 1985083dd21c6c21e44fe68d7015090b769cc25f Mon Sep 17 00:00:00 2001 From: Rupert Bates Date: Mon, 7 Oct 2024 14:44:48 +0100 Subject: [PATCH] Get rid of warnings --- .../app/actions/CachedActionBuilder.scala | 2 +- .../app/actions/NoCacheActionBuilder.scala | 2 +- .../app/actions/PrivateActionBuilder.scala | 2 +- .../gu/support/paperround/PaperRound.scala | 2 +- .../AnnualisedValueTwoCalculator.scala | 2 +- .../src/main/scala/MyApplicationLoader.scala | 3 +- .../scala/model/stripe/StripeRequest.scala | 2 +- .../services/ContributionsStoreService.scala | 2 +- .../scala/backend/StripeBackendSpec.scala | 90 ++++++++++--------- .../controllers/PaypalControllerSpec.scala | 6 +- .../controllers/StripeControllerSpec.scala | 2 +- .../ContributionsStoreServiceSpec.scala | 9 +- .../scala/services/EmailServiceSpec.scala | 47 +++++----- 13 files changed, 89 insertions(+), 82 deletions(-) diff --git a/support-frontend/app/actions/CachedActionBuilder.scala b/support-frontend/app/actions/CachedActionBuilder.scala index aefa09cc120..222900414c8 100644 --- a/support-frontend/app/actions/CachedActionBuilder.scala +++ b/support-frontend/app/actions/CachedActionBuilder.scala @@ -16,7 +16,7 @@ class CachedActionBuilder( implicit private val ec: ExecutionContext = executionContext private val maximumBrowserAge = 1.minute - override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] = + override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] = block(request).map(_.withHeaders(mergeHeader("Vary", cacheHeaders() ++ headers): _*)) private def cacheHeaders(now: DateTime = DateTime.now): List[(String, String)] = { diff --git a/support-frontend/app/actions/NoCacheActionBuilder.scala b/support-frontend/app/actions/NoCacheActionBuilder.scala index 420d61076f0..da887d7eca1 100644 --- a/support-frontend/app/actions/NoCacheActionBuilder.scala +++ b/support-frontend/app/actions/NoCacheActionBuilder.scala @@ -11,7 +11,7 @@ class NoCacheActionBuilder( ) extends ActionBuilder[Request, AnyContent] { implicit private val ec: ExecutionContext = executionContext - override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] = + override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] = block(request).map(_.withHeaders(mergeHeader("Vary", List(CacheControl.noCache) ++ headers): _*)) } diff --git a/support-frontend/app/actions/PrivateActionBuilder.scala b/support-frontend/app/actions/PrivateActionBuilder.scala index b8250fbc7fa..38976399499 100644 --- a/support-frontend/app/actions/PrivateActionBuilder.scala +++ b/support-frontend/app/actions/PrivateActionBuilder.scala @@ -18,6 +18,6 @@ class PrivateActionBuilder( override def composeAction[A](action: Action[A]): Action[A] = new CSRFAction(action, csrfConfig, addToken, checkToken) - override def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]): Future[Result] = + override def invokeBlock[A](request: Request[A], block: Request[A] => Future[Result]): Future[Result] = block(request).map(_.withHeaders(CacheControl.noCache)) } diff --git a/support-models/src/main/scala/com/gu/support/paperround/PaperRound.scala b/support-models/src/main/scala/com/gu/support/paperround/PaperRound.scala index c46b1800422..84d6dc618f6 100644 --- a/support-models/src/main/scala/com/gu/support/paperround/PaperRound.scala +++ b/support-models/src/main/scala/com/gu/support/paperround/PaperRound.scala @@ -15,7 +15,7 @@ trait PaperRoundAPI { def chargebands(): Future[ChargeBandsEndpoint.Response] } -case class AgentId(val id: BigInt) extends AnyVal +case class AgentId(id: BigInt) extends AnyVal object AgentId { implicit val encoder: Encoder[AgentId] = Encoder.encodeBigInt.contramap(_.id) diff --git a/support-modules/acquisition-events/src/main/scala/com/gu/support/acquisitions/calculator/AnnualisedValueTwoCalculator.scala b/support-modules/acquisition-events/src/main/scala/com/gu/support/acquisitions/calculator/AnnualisedValueTwoCalculator.scala index f2195e2a456..43799b8900b 100644 --- a/support-modules/acquisition-events/src/main/scala/com/gu/support/acquisitions/calculator/AnnualisedValueTwoCalculator.scala +++ b/support-modules/acquisition-events/src/main/scala/com/gu/support/acquisitions/calculator/AnnualisedValueTwoCalculator.scala @@ -152,7 +152,7 @@ object AnnualisedValueTwoCalculator { }) .getOrElse(Left("No print options supplied")) - def getMargin(a: AcquisitionModel) = + private def getMargin(a: AcquisitionModel) = a.product match { case AcquisitionProduct.Contribution => getContributionMargin(a) case AcquisitionProduct.RecurringContribution => getRecurringMargin(a) diff --git a/support-payment-api/src/main/scala/MyApplicationLoader.scala b/support-payment-api/src/main/scala/MyApplicationLoader.scala index bc6c1fd8180..4ed28c4869a 100644 --- a/support-payment-api/src/main/scala/MyApplicationLoader.scala +++ b/support-payment-api/src/main/scala/MyApplicationLoader.scala @@ -30,10 +30,9 @@ class MyApplicationLoader extends ApplicationLoader with StrictLogging { try { new MyComponents(context).application } catch { - case err: Throwable => { + case err: Throwable => logger.error("Could not start application", err) throw err - } } } } diff --git a/support-payment-api/src/main/scala/model/stripe/StripeRequest.scala b/support-payment-api/src/main/scala/model/stripe/StripeRequest.scala index f05bed68a72..efde9f22664 100644 --- a/support-payment-api/src/main/scala/model/stripe/StripeRequest.scala +++ b/support-payment-api/src/main/scala/model/stripe/StripeRequest.scala @@ -82,7 +82,7 @@ object StripeJsonDecoder { // Private because it should only be constructed using the accompanying Decoder class NonEmptyString private (val value: String) extends AnyVal { - override def toString(): String = value + override def toString: String = value } object NonEmptyString { diff --git a/support-payment-api/src/main/scala/services/ContributionsStoreService.scala b/support-payment-api/src/main/scala/services/ContributionsStoreService.scala index d7ef541fdc2..9aa394fcad9 100644 --- a/support-payment-api/src/main/scala/services/ContributionsStoreService.scala +++ b/support-payment-api/src/main/scala/services/ContributionsStoreService.scala @@ -13,7 +13,7 @@ import model.{InitializationError, InitializationResult, SQSThreadPool} import services.ContributionsStoreQueueService.Message import java.time.LocalDateTime -import scala.collection.JavaConverters._ +import scala.jdk.CollectionConverters._ import scala.concurrent.Future import scala.util.control.NonFatal diff --git a/support-payment-api/src/test/scala/backend/StripeBackendSpec.scala b/support-payment-api/src/test/scala/backend/StripeBackendSpec.scala index c6fd79f7662..b999a44ab82 100644 --- a/support-payment-api/src/test/scala/backend/StripeBackendSpec.scala +++ b/support-payment-api/src/test/scala/backend/StripeBackendSpec.scala @@ -33,10 +33,10 @@ import scala.concurrent.{ExecutionContext, Future} class StripeBackendFixture(implicit ec: ExecutionContext) extends MockitoSugar { // -- entities - val email = Json.fromString("email@email.com").as[NonEmptyString].toOption.get - val token = Json.fromString("token").as[NonEmptyString].toOption.get + val email: NonEmptyString = Json.fromString("email@email.com").as[NonEmptyString].toOption.get + val token: NonEmptyString = Json.fromString("token").as[NonEmptyString].toOption.get val recaptchaToken = "recaptchaToken" - val acquisitionData = + val acquisitionData: AcquisitionData = AcquisitionData( Some("platform"), None, @@ -53,11 +53,12 @@ class StripeBackendFixture(implicit ec: ExecutionContext) extends MockitoSugar { None, Some("N1 9GU"), ) - val stripePaymentData = StripePaymentData(email, Currency.USD, 12, None) - val legacyStripePaymentData = LegacyStripePaymentData(email, Currency.USD, 12, None, token) - val stripePublicKey = StripePublicKey("pk_test_FOOBAR") - val stripeChargeRequest = LegacyStripeChargeRequest(legacyStripePaymentData, acquisitionData, Some(stripePublicKey)) - val createPaymentIntent = + val stripePaymentData: StripePaymentData = StripePaymentData(email, Currency.USD, 12, None) + val legacyStripePaymentData: LegacyStripePaymentData = LegacyStripePaymentData(email, Currency.USD, 12, None, token) + val stripePublicKey: StripePublicKey = StripePublicKey("pk_test_FOOBAR") + val stripeChargeRequest: LegacyStripeChargeRequest = + LegacyStripeChargeRequest(legacyStripePaymentData, acquisitionData, Some(stripePublicKey)) + val createPaymentIntent: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentData, @@ -65,30 +66,30 @@ class StripeBackendFixture(implicit ec: ExecutionContext) extends MockitoSugar { Some(stripePublicKey), recaptchaToken, ) - val confirmPaymentIntent = + val confirmPaymentIntent: ConfirmPaymentIntent = ConfirmPaymentIntent("id", stripePaymentData, acquisitionData, Some(stripePublicKey)) - val countrySubdivisionCode = Some("NY") - val clientBrowserInfo = ClientBrowserInfo("", "", None, None, countrySubdivisionCode) - val stripeHookObject = StripeHookObject("id", "GBP") - val stripeHookData = StripeHookData(stripeHookObject) - val stripeHook = StripeRefundHook("id", PaymentStatus.Paid, stripeHookData) - val dbError = ContributionsStoreService.Error(new Exception("DB error response")) + val countrySubdivisionCode: Option[String] = Some("NY") + val clientBrowserInfo: ClientBrowserInfo = ClientBrowserInfo("", "", None, None, countrySubdivisionCode) + val stripeHookObject: StripeHookObject = StripeHookObject("id", "GBP") + val stripeHookData: StripeHookData = StripeHookData(stripeHookObject) + val stripeHook: StripeRefundHook = StripeRefundHook("id", PaymentStatus.Paid, stripeHookData) + val dbError: ContributionsStoreService.Error = ContributionsStoreService.Error(new Exception("DB error response")) - val identityError = IdentityClient.ContextualError( + val identityError: IdentityClient.ContextualError = IdentityClient.ContextualError( IdentityClient.Error.fromThrowable(new Exception("Identity error response")), IdentityClient.GetUser("test@theguardian.com"), ) val stripeDisabledErrorText = "Stripe payments are currently disabled" - val paymentError = PaypalApiError.fromString("Error response") - val stripeApiError = StripeApiError.fromThrowable(new Exception("Stripe error"), None) - val backendError = BackendError.fromStripeApiError(stripeApiError) + val paymentError: PaypalApiError = PaypalApiError.fromString("Error response") + val stripeApiError: StripeApiError = StripeApiError.fromThrowable(new Exception("Stripe error"), None) + val backendError: BackendError = BackendError.fromStripeApiError(stripeApiError) val emailError: EmailService.Error = EmailService.Error(new Exception("Email error response")) // -- mocks val chargeMock: Charge = mock[Charge] - val eventMock = mock[Event] - val paymentIntentMock = mock[PaymentIntent] + val eventMock: Event = mock[Event] + val paymentIntentMock: PaymentIntent = mock[PaymentIntent] // -- service responses val paymentServiceResponse: EitherT[Future, StripeApiError, Charge] = @@ -250,8 +251,9 @@ class StripeBackendSpec "a request is made to create a Payment Intent" should { "return Stripe payments are currently disabled response if stripe checkout switch is off in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithStripe = StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout)) - val createPaymentIntentWithStripeCheckout = + val stripePaymentDataWithStripe: StripePaymentData = + StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout)) + val createPaymentIntentWithStripeCheckout: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripe, @@ -266,8 +268,9 @@ class StripeBackendSpec } "return Stripe payments are currently disabled response if stripe Apple Pay switch is off in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithApplePay = StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay)) - val createPaymentIntentWithStripeApplePay = + val stripePaymentDataWithApplePay: StripePaymentData = + StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay)) + val createPaymentIntentWithStripeApplePay: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithApplePay, @@ -281,9 +284,9 @@ class StripeBackendSpec StripeApiError.fromString(stripeDisabledErrorText, None) } "return Stripe payments are currently disabled response if stripe payment request button switch is off in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithStripePaymentRequest = + val stripePaymentDataWithStripePaymentRequest: StripePaymentData = StripePaymentData(email, Currency.USD, 12, Some(StripePaymentRequestButton)) - val createPaymentIntentWithStripePaymentRequest = + val createPaymentIntentWithStripePaymentRequest: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripePaymentRequest, @@ -299,8 +302,9 @@ class StripeBackendSpec StripeApiError.fromString(stripeDisabledErrorText, None) } "return Success if stripe checkout switch is On in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithStripe = StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout)) - val createPaymentIntentWithStripeCheckout = + val stripePaymentDataWithStripe: StripePaymentData = + StripePaymentData(email, Currency.USD, 12, Some(StripeCheckout)) + val createPaymentIntentWithStripeCheckout: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripe, @@ -331,8 +335,9 @@ class StripeBackendSpec } "return Success if stripe apple pay switch is On in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithStripeApplePay = StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay)) - val createPaymentIntentWithStripeApplePay = + val stripePaymentDataWithStripeApplePay: StripePaymentData = + StripePaymentData(email, Currency.USD, 12, Some(StripeApplePay)) + val createPaymentIntentWithStripeApplePay: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripeApplePay, @@ -361,9 +366,9 @@ class StripeBackendSpec StripePaymentIntentsApiResponse.Success() } "return Success if stripe payment request button switch is On in support-admin-console" in new StripeBackendFixture { - val stripePaymentDataWithStripePaymentRequest = + val stripePaymentDataWithStripePaymentRequest: StripePaymentData = StripePaymentData(email, Currency.USD, 12, Some(StripePaymentRequestButton)) - val createPaymentIntentWithStripePaymentRequest = + val createPaymentIntentWithStripePaymentRequest: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripePaymentRequest, @@ -398,9 +403,10 @@ class StripeBackendSpec "a request is made to create a charge/payment" should { "return error if the email address is invalid due to a comma in it" in new StripeBackendFixture { - val emailWithComma = Json.fromString("email,address@email.com").as[NonEmptyString].toOption.get - val stripePaymentDataWithStripe = StripePaymentData(emailWithComma, Currency.USD, 12, Some(StripeCheckout)) - val createPaymentIntentWithStripeCheckout = + val emailWithComma: NonEmptyString = Json.fromString("email,address@email.com").as[NonEmptyString].toOption.get + val stripePaymentDataWithStripe: StripePaymentData = + StripePaymentData(emailWithComma, Currency.USD, 12, Some(StripeCheckout)) + val createPaymentIntentWithStripeCheckout: CreatePaymentIntent = CreatePaymentIntent( "payment-method-id", stripePaymentDataWithStripe, @@ -491,8 +497,9 @@ class StripeBackendSpec when(mockSoftOptInsService.sendMessage(any(), any())(any())).thenReturn(softOptInsResponse) when(mockAcquisitionsEventBusService.putAcquisitionEvent(any())) .thenReturn(acquisitionsEventBusResponse) - val trackContribution = PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution")) - val result = + val trackContribution: PrivateMethod[Future[List[BackendError]]] = + PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution")) + val result: Future[List[BackendError]] = stripeBackend invokePrivate trackContribution(chargeMock, stripeChargeRequest, None, clientBrowserInfo) result.futureValue mustBe List(BackendError.Database(dbError)) @@ -508,10 +515,11 @@ class StripeBackendSpec when(mockSoftOptInsService.sendMessage(any(), any())(any())).thenReturn(softOptInsResponse) when(mockAcquisitionsEventBusService.putAcquisitionEvent(any())) .thenReturn(acquisitionsEventBusResponseError) - val trackContribution = PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution")) - val result = + val trackContribution: PrivateMethod[Future[List[BackendError]]] = + PrivateMethod[Future[List[BackendError]]](Symbol("trackContribution")) + val result: Future[List[BackendError]] = stripeBackend invokePrivate trackContribution(chargeMock, stripeChargeRequest, None, clientBrowserInfo) - val error = List( + val error: List[BackendError] = List( BackendError.AcquisitionsEventBusError(acquisitionsEventBusErrorMessage), BackendError.Database(dbError), ) diff --git a/support-payment-api/src/test/scala/controllers/PaypalControllerSpec.scala b/support-payment-api/src/test/scala/controllers/PaypalControllerSpec.scala index 4a56342787c..c5c295f002d 100644 --- a/support-payment-api/src/test/scala/controllers/PaypalControllerSpec.scala +++ b/support-payment-api/src/test/scala/controllers/PaypalControllerSpec.scala @@ -96,13 +96,13 @@ class PaypalControllerSpec extends AnyWordSpec with Status with Matchers { implicit val materializer: Materializer = ActorMaterializer() implicit val executionContext: ExecutionContext = ExecutionContext.global - val context = ApplicationLoader.Context.create(Environment.simple()) + val context: ApplicationLoader.Context = ApplicationLoader.Context.create(Environment.simple()) "Paypal Controller" when { "a request is made to create a payment" should { - val fixtureFor200Response = new PaypalControllerFixture()(executionContext, context) { + val fixtureFor200Response: PaypalControllerFixture = new PaypalControllerFixture()(executionContext, context) { val link = new Links("http://return-url.com", "approval_url") val links: java.util.List[Links] = List(link).asJava when(enrichedPaymentMock.payment) @@ -188,7 +188,7 @@ class PaypalControllerSpec extends AnyWordSpec with Status with Matchers { } "return a 500 response if the response contains an invalid return url" in { - val fixture = new PaypalControllerFixture()(executionContext, context) { + val fixture: PaypalControllerFixture = new PaypalControllerFixture()(executionContext, context) { import scala.jdk.CollectionConverters._ diff --git a/support-payment-api/src/test/scala/controllers/StripeControllerSpec.scala b/support-payment-api/src/test/scala/controllers/StripeControllerSpec.scala index a6746b01b64..0eb110ae3a9 100644 --- a/support-payment-api/src/test/scala/controllers/StripeControllerSpec.scala +++ b/support-payment-api/src/test/scala/controllers/StripeControllerSpec.scala @@ -105,7 +105,7 @@ class StripeControllerSpec extends AnyWordSpec with Status with Matchers { implicit val materializer: Materializer = ActorMaterializer() implicit val executionContext: ExecutionContext = ExecutionContext.global - val context = ApplicationLoader.Context.create(Environment.simple()) + val context: ApplicationLoader.Context = ApplicationLoader.Context.create(Environment.simple()) "StripeController" when { diff --git a/support-payment-api/src/test/scala/services/ContributionsStoreServiceSpec.scala b/support-payment-api/src/test/scala/services/ContributionsStoreServiceSpec.scala index d277887c5bf..ecb6176e240 100644 --- a/support-payment-api/src/test/scala/services/ContributionsStoreServiceSpec.scala +++ b/support-payment-api/src/test/scala/services/ContributionsStoreServiceSpec.scala @@ -1,8 +1,9 @@ package services +import io.circe.Json + import java.time.LocalDateTime import java.util.UUID - import model.{Currency, PaymentProvider, PaymentStatus} import model.db.ContributionData import services.ContributionsStoreQueueService.NewContributionData @@ -12,9 +13,9 @@ import org.scalatest.matchers.must.Matchers class ContributionsStoreServiceSpec extends AnyFlatSpec with Matchers { - val uuid = UUID.randomUUID() + val uuid: UUID = UUID.randomUUID() - val contributionData = ContributionData( + val contributionData: ContributionData = ContributionData( paymentProvider = PaymentProvider.Paypal, paymentStatus = PaymentStatus.Paid, paymentId = "paymentId", @@ -29,7 +30,7 @@ class ContributionsStoreServiceSpec extends AnyFlatSpec with Matchers { postalCode = Some("N1 9GU"), ) - val expectedJson = parse( + val expectedJson: Json = parse( s"""|{ | "newContributionData" : { | "paymentProvider" : "Paypal", diff --git a/support-payment-api/src/test/scala/services/EmailServiceSpec.scala b/support-payment-api/src/test/scala/services/EmailServiceSpec.scala index ffe2d169d28..016a465fcb5 100644 --- a/support-payment-api/src/test/scala/services/EmailServiceSpec.scala +++ b/support-payment-api/src/test/scala/services/EmailServiceSpec.scala @@ -1,19 +1,21 @@ package services +import cats.data.EitherT import com.amazonaws.services.sqs.AmazonSQSAsync import com.amazonaws.services.sqs.model.{GetQueueUrlResult, SendMessageResult} -import com.paypal.api.payments.{Amount, Payer, PayerInfo, Payment} +import com.paypal.api.payments.{Amount, Payer, PayerInfo, Payment, Transaction} import model.{DefaultThreadPool, PaymentProvider} import org.mockito.Mockito._ import org.mockito.ArgumentMatchers.any import org.scalatest.concurrent.ScalaFutures -import java.util.concurrent.CompletableFuture +import java.util.concurrent.CompletableFuture import model.email.ContributorRow import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.must.Matchers import org.scalatestplus.mockito.MockitoSugar +import java.util import scala.compat.java8.FutureConverters._ import scala.concurrent.Future import scala.jdk.CollectionConverters._ @@ -25,21 +27,20 @@ class EmailServiceSpec extends AnyFlatSpec with Matchers with MockitoSugar with trait EmailServiceTestFixture { implicit val executionContextTest: DefaultThreadPool = DefaultThreadPool(ExecutionContext.global) - val sqsClient = mock[AmazonSQSAsync] - val getQueueUrlResult = mock[GetQueueUrlResult] - when(getQueueUrlResult.getQueueUrl()).thenReturn("test-queue-name") + val sqsClient: AmazonSQSAsync = mock[AmazonSQSAsync] + val getQueueUrlResult: GetQueueUrlResult = mock[GetQueueUrlResult] + when(getQueueUrlResult.getQueueUrl).thenReturn("test-queue-name") when(sqsClient.getQueueUrl("test-queue-name")).thenReturn(getQueueUrlResult) val emailService = new EmailService(sqsClient, "test-queue-name") } it should "send an email" in new EmailServiceTestFixture { - val payment = mock[Payment] - val amount = mock[Amount] - val payer = mock[Payer] - val payerInfo = mock[PayerInfo] - val transaction = mock[com.paypal.api.payments.Transaction] - val transactions = List(transaction).asJava - val identityId = 666L + val payment: Payment = mock[Payment] + val amount: Amount = mock[Amount] + val payer: Payer = mock[Payer] + val payerInfo: PayerInfo = mock[PayerInfo] + val transaction: Transaction = mock[com.paypal.api.payments.Transaction] + val transactions: util.List[Transaction] = List(transaction).asJava when(transaction.getAmount).thenReturn(amount) when(amount.getCurrency).thenReturn("GBP") when(amount.getTotal).thenReturn("2") @@ -50,12 +51,12 @@ class EmailServiceSpec extends AnyFlatSpec with Matchers with MockitoSugar with when(payment.getTransactions).thenReturn(transactions) when(payment.getCreateTime).thenReturn("01-01-2018T12:12:12") - val scalaFuture = Future.successful(new SendMessageResult) + val scalaFuture: Future[SendMessageResult] = Future.successful(new SendMessageResult) val javaFuture: CompletableFuture[SendMessageResult] = scalaFuture.toJava.toCompletableFuture when(sqsClient.sendMessageAsync(any())).thenReturn(javaFuture) - val emailResult = emailService.sendThankYouEmail( + val emailResult: EitherT[Future, EmailService.Error, SendMessageResult] = emailService.sendThankYouEmail( ContributorRow("email@email.com", "GBP", "1", PaymentProvider.Paypal, None, BigDecimal(2)), ) whenReady(emailResult.value) { result => @@ -64,13 +65,12 @@ class EmailServiceSpec extends AnyFlatSpec with Matchers with MockitoSugar with } it should "return an error if the sqs client throws an exception" in new EmailServiceTestFixture { - val payment = mock[Payment] - val amount = mock[Amount] - val payer = mock[Payer] - val payerInfo = mock[PayerInfo] - val transaction = mock[com.paypal.api.payments.Transaction] - val transactions = List(transaction).asJava - val identityId = 666L + val payment: Payment = mock[Payment] + val amount: Amount = mock[Amount] + val payer: Payer = mock[Payer] + val payerInfo: PayerInfo = mock[PayerInfo] + val transaction: Transaction = mock[com.paypal.api.payments.Transaction] + val transactions: util.List[Transaction] = List(transaction).asJava when(transaction.getAmount).thenReturn(amount) when(amount.getCurrency).thenReturn("GBP") when(amount.getTotal).thenReturn("2") @@ -83,8 +83,7 @@ class EmailServiceSpec extends AnyFlatSpec with Matchers with MockitoSugar with val errorString = "Any sqs client error" val exception = new Exception(errorString) - val emailError = EmailService.Error(exception) - val scalaFuture = Future.failed[SendMessageResult](exception) + val scalaFuture: Future[SendMessageResult] = Future.failed[SendMessageResult](exception) val javaFuture: CompletableFuture[SendMessageResult] = scalaFuture.toJava.toCompletableFuture when(sqsClient.sendMessageAsync(any())).thenReturn(javaFuture) @@ -99,7 +98,7 @@ class EmailServiceSpec extends AnyFlatSpec with Matchers with MockitoSugar with // TODO: understand how this java.lang.Exception bit gets added error.getMessage mustBe s"java.lang.Exception: $errorString" }, - success => fail(), + _ => fail(), ) } }