From e1ba5413d2c1a8547d41a382ad1eda0a59d92309 Mon Sep 17 00:00:00 2001 From: fluency03 Date: Mon, 30 Apr 2018 03:13:19 +0200 Subject: [PATCH] add PackageTest for routes --- .../blockchain/api/routes/PackageTest.scala | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/scala/com/fluency03/blockchain/api/routes/PackageTest.scala diff --git a/src/test/scala/com/fluency03/blockchain/api/routes/PackageTest.scala b/src/test/scala/com/fluency03/blockchain/api/routes/PackageTest.scala new file mode 100644 index 0000000..7bdd92c --- /dev/null +++ b/src/test/scala/com/fluency03/blockchain/api/routes/PackageTest.scala @@ -0,0 +1,33 @@ +package com.fluency03.blockchain.api.routes + +import akka.http.scaladsl.model.StatusCodes +import com.fluency03.blockchain.api.{FailureMsg, SuccessMsg} +import org.scalatest.{FlatSpec, Matchers} + +class PackageTest extends FlatSpec with Matchers { + + "failsafeMsg" should "return corresponding message based on success/failure of the function." in { + failsafeMsg({ + throw new Exception("some error") + "some string" + }) shouldEqual FailureMsg("some error") + + failsafeMsg({ + "some string" + }) shouldEqual SuccessMsg("some string") + + } + + "failsafeResp" should "return corresponding message based on success/failure of the function." in { + failsafeResp({ + throw new Exception("some error") + "some string" + }) shouldEqual (StatusCodes.InternalServerError, FailureMsg("some error")) + + failsafeResp({ + "some string" + }) shouldEqual (StatusCodes.OK, SuccessMsg("some string")) + + } + +}