diff options
author | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
---|---|---|
committer | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
commit | 9968eaefa2a97ebe495fa51b640e31c78db61ac6 (patch) | |
tree | 4eed12a4ebb2829e336a3da673c7c8462e7ab845 /src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala | |
parent | d5ecec043a3d70dd09bda8a79fcd188f411b47df (diff) | |
parent | d4b18efda238f506103dddbf3b400ae17c797276 (diff) | |
download | rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.gz rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.bz2 rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.zip |
Merge branch 'master' into slick-query-builder
Diffstat (limited to 'src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala')
-rw-r--r-- | src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala new file mode 100644 index 0000000..4892b95 --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/TestUtils.scala @@ -0,0 +1,52 @@ +package xyz.driver.pdsuicommon.parsers + +import org.scalacheck.Prop +import org.scalacheck.Prop.BooleanOperators +import org.scalatest.matchers.{MatchResult, Matcher} +import xyz.driver.pdsuicommon.utils.Utils + +import scala.reflect.ClassTag +import scala.util.{Failure, Success, Try} + +object TestUtils { + + object success extends Matcher[Try[Any]] { + override def apply(left: Try[Any]) = { + MatchResult(left.isSuccess, s"$left did not fail", s"did fail with $left") + } + } + + class FailWith[ThrowableT <: Throwable](implicit ct: ClassTag[ThrowableT]) extends Matcher[Try[Any]] { + override def apply(left: Try[Any]): MatchResult = { + MatchResult( + left.isFailure && left.failed.get.getClass == ct.runtimeClass, + left match { + case Success(x) => s"$left did not fail" + case Failure(e) => s"$left did fail with ${Utils.getClassSimpleName(e.getClass)}, " + + s"not ${Utils.getClassSimpleName(ct.runtimeClass)}" + }, + left match { + case Success(_) => s"$left failed with ${Utils.getClassSimpleName(ct.runtimeClass)}" + case Failure(e) => s"$left failed with ${Utils.getClassSimpleName(e.getClass)}" + } + ) + } + } + + def failWith[ThrowableT <:Throwable](implicit ct: ClassTag[ThrowableT]) = new FailWith[ThrowableT] + + final implicit class TryPropOps(val self: Try[Any]) extends AnyVal { + + def successProp: Prop = self match { + case Success(_) => true :| "ok" + case Failure(e) => false :| e.getMessage + } + + def failureProp: Prop = self match { + case Success(x) => false :| s"invalid: $x" + case Failure(e) => true + } + + } + +} |