]> git.saurik.com Git - redis.git/blob - client-libraries/scala/src/test/scala/com/redis/operations/OperationsSpec.scala
7fe26be3d0fabf8e408f3549b93d42ce71888020
[redis.git] / client-libraries / scala / src / test / scala / com / redis / operations / OperationsSpec.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
8 object OperationsSpec extends Specification with Mockito {
9
10 "Redis Client Operations" should {
11
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 "set a key" in {
21 connection.readBoolean returns true
22 client.set("a", "b") mustEqual true
23 connection.write("SET a 1\r\nb\r\n") was called
24 }
25
26 "set a key with setKey" in {
27 connection.readBoolean returns true
28 client.setKey("a", "b") mustEqual true
29 connection.write("SET a 1\r\nb\r\n") was called
30 }
31
32 "set a key with expiration" in {
33 connection.readBoolean returns true
34 client.set("a", "b", 4) mustEqual true
35 connection.write("SET a 1\r\nb\r\n") was called
36 connection.write("EXPIRE a 4\r\n") was called
37 }
38
39 "expire a key" in {
40 connection.readBoolean returns true
41 client.expire("a", 4) mustEqual true
42 connection.write("EXPIRE a 4\r\n") was called
43 }
44
45 "get a key" in {
46 connection.readResponse returns "b"
47 client.get("a") mustEqual "b"
48 connection.write("GET a\r\n") was called
49 }
50
51 "get and set a key" in {
52 connection.readResponse returns "old"
53 client.getSet("a", "new") mustEqual "old"
54 connection.write("GETSET a 3\r\nnew\r\n") was called
55 }
56
57 "delete a key" in {
58 connection.readBoolean returns true
59 client.delete("a") mustEqual true
60 connection.write("DEL a\r\n") was called
61 }
62
63 "tell if a key exists" in {
64 connection.readBoolean returns true
65 client.exists("a") mustEqual true
66 connection.write("EXISTS a\r\n") was called
67 }
68
69 "tell if a key exists" in {
70 connection.readBoolean returns true
71 client.exists("a") mustEqual true
72 connection.write("EXISTS a\r\n") was called
73 }
74
75 "increment a value" in {
76 connection.readInt returns 1
77 client.incr("a") mustEqual 1
78 connection.write("INCR a\r\n") was called
79 }
80
81 "increment a value by N" in {
82 connection.readInt returns 27
83 client.incr("a", 23) mustEqual 27
84 connection.write("INCRBY a 23\r\n") was called
85 }
86
87 "decrement a value" in {
88 connection.readInt returns 0
89 client.decr("a") mustEqual 0
90 connection.write("DECR a\r\n") was called
91 }
92
93 "decrement a value by N" in {
94 connection.readInt returns 25
95 client.decr("a", 2) mustEqual 25
96 connection.write("DECRBY a 2\r\n") was called
97 }
98
99 "return type of key" in {
100 connection.readResponse returns "String"
101 client.getType("a") mustEqual "String"
102 connection.write("TYPE a\r\n") was called
103 }
104 }
105 }