Permalink
Browse files

Move ItemIdListSpec out of KestrelHandlerSpec

- have ItemIdListSpec in its own file
- make tests more simple and readable
  • Loading branch information...
1 parent 7a13809 commit a45e2ced1e462a11eddd45147f930200227d7135 @rvoicilas rvoicilas committed Aug 31, 2012
View
56 src/test/scala/net/lag/kestrel/ItemIdListSpec.scala
@@ -0,0 +1,56 @@
+package net.lag.kestrel
+
+import org.specs.Specification
+
+class ItemIdListSpec extends Specification {
+ "ItemIdList" should {
+ var iil = new ItemIdList()
+
+ doBefore {
+ iil = new ItemIdList()
+ }
+
+ "add an Integer to the list" in {
+ iil.add(3)
+ iil.size mustEqual 1
+ }
+
+ "add a sequence of Integers to the list" in {
+ iil.add(Seq(1, 2, 3, 4))
+ iil.size mustEqual 4
+ }
+
+ "pop one item at a time" in {
+ iil.add(Seq(90, 99))
+ iil.pop() mustEqual Some(90)
+ iil.pop() mustEqual Some(99)
+ }
+
+ "pop None when there's nothing to pop" in {
+ iil.pop() mustEqual None
+ }
+
+ "pop all items from an index upward" in {
+ iil.add(Seq(1, 2, 3, 4))
+ val expected = Seq(1, 2)
+ val actual = iil.pop(2)
+ expected mustEqual actual
+ }
+
+ "pop all items from the list" in {
+ val seq = Seq(12, 13, 14)
+ iil.add(seq)
+ seq mustEqual iil.popAll()
+ }
+
+ "return empty seq when pop's count is invalid" in {
+ iil.pop(1) mustEqual Seq()
+ }
+
+ "remove a set of items from the list" in {
+ iil.add(Seq(19, 7, 20, 22))
+ val expected = Set(7, 20, 22)
+ expected mustEqual iil.remove(expected)
+ }
+ }
+}
View
30 src/test/scala/net/lag/kestrel/KestrelHandlerSpec.scala
@@ -32,36 +32,6 @@ import config._
class FakeKestrelHandler(queues: QueueCollection, maxOpenTransactions: Int)
extends KestrelHandler(queues, maxOpenTransactions, () => "none", 0) with SimplePendingReads
-class ItemIdListSpec extends Specification with TestLogging {
- "ItemIdList" should {
- "add and pop" in {
- val x = new ItemIdList()
- x.add(Seq(5, 4))
- x.size mustEqual 2
- x.pop() mustEqual Some(5)
- x.pop() mustEqual Some(4)
- x.pop() mustEqual None
- }
-
- "remove from the middle" in {
- val x = new ItemIdList()
- x.add(Seq(7, 6, 5, 4, 3, 2))
- x.pop() mustEqual Some(7)
- x.remove(Set(5, 4, 2)) mustEqual Set(5, 4, 2)
- x.popAll() mustEqual Seq(6, 3)
- }
-
- "remove and pop combined" in {
- val x = new ItemIdList()
- x.add(Seq(7, 6, 5, 4, 3, 2))
- x.remove(Set(6)) mustEqual Set(6)
- x.pop() mustEqual Some(7)
- x.pop() mustEqual Some(5)
- x.popAll() mustEqual Seq(4, 3, 2)
- }
- }
-}
-
class KestrelHandlerSpec extends Specification with TempFolder with TestLogging {
val config = new QueueBuilder().apply()

0 comments on commit a45e2ce

Please sign in to comment.