]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/test/scala/com/redis/operations/ListOperationsSpec.scala
95c66b55b71e4da45e00684af2b92f9366314362
[redis.git] / client-libraries / scala / src / test / scala / com / redis / operations / ListOperationsSpec.scala
1 import org.specs._
2 import com.redis._
3
4 import org.specs.mock.Mockito
5 import org.mockito.Mock._
6 import org.mockito.Mockito._
7 import org.mockito.Mockito.doNothing
8
9 object ListOperationsSpec extends Specification with Mockito {
10
11 "Redis Client List Operations" should {
12 var client: RedisTestClient = null
13 var connection: Connection = null
14
15 doBefore{
16 connection = mock[Connection]
17 client = new RedisTestClient(connection)
18 }
19
20 "push to head" in {
21 connection.readBoolean returns true
22 client.pushHead("k", "v") must beTrue
23 connection.write("LPUSH k 1\r\nv\r\n") was called
24 }
25
26 "push to tail" in {
27 connection.readBoolean returns true
28 client.pushTail("k", "v") must beTrue
29 connection.write("RPUSH k 1\r\nv\r\n") was called
30 }
31
32 "pop from head" in {
33 connection.readString returns "value"
34 client.popHead("key") mustEqual "value"
35 connection.write("LPOP key\r\n") was called
36 }
37
38 "pop from tail" in {
39 connection.readString returns "value"
40 client.popTail("key") mustEqual "value"
41 connection.write("RPOP key\r\n") was called
42 }
43
44 "return list index" in {
45 connection.readString returns "value"
46 client.listIndex("k", 2) mustEqual "value"
47 connection.write("LINDEX k 2\r\n") was called
48 }
49
50 "return set element at index" in {
51 connection.readBoolean returns true
52 client.listSet("k", 1, "value") mustEqual true
53 connection.write("LSET k 1 5\r\nvalue\r\n") was called
54 }
55
56 "return list size" in {
57 connection.readInt returns 3
58 client.listLength("k") mustEqual 3
59 connection.write("LLEN k\r\n") was called
60 }
61
62 "return list range" in {
63 val listResult: List[String] = List("one", "two", "three", "four", "five")
64 connection.readList returns listResult
65 client.listRange("k", 2, 4) mustEqual listResult
66 connection.write("LRANGE k 2 4\r\n") was called
67 }
68
69 "trim a list" in {
70 connection.readBoolean returns true
71 client.listTrim("k", 2, 4) mustEqual true
72 connection.write("LTRIM k 2 4\r\n") was called
73 }
74
75 "remove occurrences of a value in the list" in {
76 connection.readBoolean returns true
77 client.listRem("k", 2, "value") mustEqual true
78 connection.write("LREM k 2 5\r\nvalue\r\n") was called
79 }
80 }
81 }