Skip to content

Instantly share code, notes, and snippets.

@vigneshwaranr
Created February 14, 2021 10:35
Show Gist options
  • Select an option

  • Save vigneshwaranr/9c989a5233bf3657a8426c55e8239748 to your computer and use it in GitHub Desktop.

Select an option

Save vigneshwaranr/9c989a5233bf3657a8426c55e8239748 to your computer and use it in GitHub Desktop.

Revisions

  1. @vigneshwaran-raveendran vigneshwaran-raveendran created this gist Feb 14, 2021.
    7 changes: 7 additions & 0 deletions good-future-apply-1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    def send(message: Message): Future[Boolean] = {
    if (isValid(message)) {
    producer.send(message).recover({case _ => false})
    } else {
    Future.successful(false) // fixed :)
    }
    }
    10 changes: 10 additions & 0 deletions good-future-apply-2.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    class UnitTest extends mutable.Specification with Mockito {
    "Module" should {
    "return false if producer throw exception" in {
    val producer = mock[Producer]
    val module = new Module(producer)
    producer.send(any) returns Future.failed(new Exception("failed")) // fixed :)
    module.send(mock[Message]) must beEqualTo(false).await
    }
    }
    }