Skip to content

Commit 4a24a7f

Browse files
committed
adds redis list string test
1 parent 71ee884 commit 4a24a7f

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2017 Otávio Santana and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Apache License v2.0 which accompanies this distribution.
6+
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7+
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
8+
*
9+
* You may elect to redistribute this code under either of these licenses.
10+
*
11+
* Contributors:
12+
*
13+
* Otavio Santana
14+
*/
15+
16+
package org.jnosql.diana.redis.key;
17+
18+
import org.jnosql.diana.api.key.BucketManagerFactory;
19+
import org.junit.After;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
import java.util.Arrays;
24+
import java.util.List;
25+
26+
import static org.junit.Assert.assertEquals;
27+
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.Assert.assertTrue;
30+
31+
32+
public class RedisListStringTest {
33+
34+
35+
private static final String FRUITS = "fruits-string";
36+
37+
private BucketManagerFactory keyValueEntityManagerFactory;
38+
39+
private List<String> fruits;
40+
41+
@Before
42+
public void init() {
43+
keyValueEntityManagerFactory = RedisTestUtils.get();
44+
fruits = keyValueEntityManagerFactory.getList(FRUITS, String.class);
45+
}
46+
47+
@Test
48+
public void shouldReturnsList() {
49+
assertNotNull(fruits);
50+
}
51+
52+
@Test
53+
public void shouldAddList() {
54+
assertTrue(fruits.isEmpty());
55+
fruits.add("banana");
56+
assertFalse(fruits.isEmpty());
57+
String banana = fruits.get(0);
58+
assertNotNull(banana);
59+
assertEquals(banana, "banana");
60+
}
61+
62+
@Test
63+
public void shouldSetList() {
64+
65+
fruits.add("banana");
66+
fruits.add(0, "orange");
67+
assertTrue(fruits.size() == 2);
68+
69+
assertEquals(fruits.get(0), "orange");
70+
assertEquals(fruits.get(1), "banana");
71+
72+
fruits.set(0, "waterMelon");
73+
assertEquals(fruits.get(0), "waterMelon");
74+
assertEquals(fruits.get(1), "banana");
75+
76+
}
77+
78+
@Test
79+
public void shouldRemoveList() {
80+
fruits.add("banana");
81+
}
82+
83+
@Test
84+
public void shouldReturnIndexOf() {
85+
86+
fruits.add("orange");
87+
fruits.add("banana");
88+
fruits.add("watermellon");
89+
fruits.add("banana");
90+
assertTrue(fruits.indexOf("banana") == 1);
91+
assertTrue(fruits.lastIndexOf("banana") == 3);
92+
93+
assertTrue(fruits.contains("banana"));
94+
assertTrue(fruits.indexOf("melon") == -1);
95+
assertTrue(fruits.lastIndexOf("melon") == -1);
96+
}
97+
98+
@Test
99+
public void shouldReturnContains() {
100+
101+
fruits.add("orange");
102+
fruits.add("banana");
103+
fruits.add("watermellon");
104+
assertTrue(fruits.contains("banana"));
105+
assertFalse(fruits.contains("melon"));
106+
assertTrue(fruits.containsAll(Arrays.asList("banana", "orange")));
107+
assertFalse(fruits.containsAll(Arrays.asList("banana", "melon")));
108+
109+
}
110+
111+
@SuppressWarnings("unused")
112+
@Test
113+
public void shouldIterate() {
114+
fruits.add("melon");
115+
fruits.add("banana");
116+
int count = 0;
117+
for (String fruiCart : fruits) {
118+
count++;
119+
}
120+
assertTrue(count == 2);
121+
fruits.remove(0);
122+
fruits.remove(0);
123+
count = 0;
124+
for (String fruiCart : fruits) {
125+
count++;
126+
}
127+
assertTrue(count == 0);
128+
}
129+
130+
@After
131+
public void end() {
132+
fruits.clear();
133+
}
134+
}

redis-driver/src/test/java/org/jnosql/diana/redis/key/RedisSetStringTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class RedisSetStringTest {
3535
@Before
3636
public void init() {
3737
keyValueEntityManagerFactory = RedisTestUtils.get();
38-
users = keyValueEntityManagerFactory.getSet("social-media", String.class);
38+
users = keyValueEntityManagerFactory.getSet("social-media-string", String.class);
3939
}
4040

4141
@Test

0 commit comments

Comments
 (0)