From 5695f2f856e74b0d3cb65765ccee85c2493def29 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 13 Apr 2015 13:31:18 -0700 Subject: add specs for some utilities --- src/test/scala/RichInstantSpec.scala | 26 ++++++++++++++++++++++++++ src/test/scala/RichTraversableOnceSpec.scala | 15 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/scala/RichInstantSpec.scala create mode 100644 src/test/scala/RichTraversableOnceSpec.scala diff --git a/src/test/scala/RichInstantSpec.scala b/src/test/scala/RichInstantSpec.scala new file mode 100644 index 0000000..41ded96 --- /dev/null +++ b/src/test/scala/RichInstantSpec.scala @@ -0,0 +1,26 @@ +import java.time._ +import org.specs2.mutable._ +import com.getbootstrap.no_carrier.util.RichInstant + +class RichInstantSpec extends Specification { + val oneDay = Duration.ofDays(1) + val twoDays = Duration.ofDays(2) + val twoDaysAndOneSec = twoDays.plusSeconds(1) + val threeDays = Duration.ofDays(3) + + "isBeyondTimeout" should { + "be false when no time has elapsed" in { + (Instant.now() isBeyondTimeout twoDays) must beFalse + } + "be false when just a bit of time has elapsed" in { + (Instant.now().minus(oneDay) isBeyondTimeout twoDays) must beFalse + } + "be false at the exact instant that the timeout has elapsed" in { + (Instant.now().minus(twoDays) isBeyondTimeout twoDays) must beFalse + } + "be true after the timeout has expired" in { + (Instant.now().minus(twoDaysAndOneSec) isBeyondTimeout twoDays) must beTrue + (Instant.now().minus(threeDays) isBeyondTimeout twoDays) must beTrue + } + } +} diff --git a/src/test/scala/RichTraversableOnceSpec.scala b/src/test/scala/RichTraversableOnceSpec.scala new file mode 100644 index 0000000..8f236ee --- /dev/null +++ b/src/test/scala/RichTraversableOnceSpec.scala @@ -0,0 +1,15 @@ +import org.specs2.mutable._ +import com.getbootstrap.no_carrier.util.RichTraversableOnce + +class RichTraversableOnceSpec extends Specification { + "maxOption" should { + "be None when the collection is empty" in { + val emptySeq: Seq[Int] = Seq() + emptySeq.maxOption must beNone + } + "be the maximum when the collection is non-empty" in { + Seq(7).maxOption mustEqual Some(7) + Seq(1, 2, 6, 5, 4).maxOption mustEqual Some(6) + } + } +} -- cgit v1.2.3