diff options
author | Chris Rebert <code@rebertia.com> | 2015-04-13 23:31:18 +0300 |
---|---|---|
committer | Chris Rebert <code@rebertia.com> | 2015-04-13 23:31:18 +0300 |
commit | 5695f2f856e74b0d3cb65765ccee85c2493def29 (patch) | |
tree | 1c5e3709c7b9d1e4238c49c0796d70b61e390bf8 /src | |
parent | 110953213638fa46290c48289f06962f70866582 (diff) |
add specs for some utilities
Diffstat (limited to 'src')
-rw-r--r-- | src/test/scala/RichInstantSpec.scala | 26 | ||||
-rw-r--r-- | src/test/scala/RichTraversableOnceSpec.scala | 15 |
2 files changed, 41 insertions, 0 deletions
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) + } + } +} |