Skip to content

Commit 1af4700

Browse files
committed
add unit tests for Utils
1 parent ce16f68 commit 1af4700

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.redislabs.redisgraph.impl;
2+
3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
import java.util.IllegalFormatConversionException;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import org.junit.Assert;
10+
import org.junit.Test;
11+
12+
public class UtilsTest {
13+
14+
@Test
15+
public void testPrepareProcedure() {
16+
17+
Assert.assertEquals("CALL prc()", Utils.prepareProcedure("prc", Arrays.asList(new String[]{}), new HashMap<>()));
18+
19+
Assert.assertEquals("CALL prc(\"a\",\"b\")", Utils.prepareProcedure("prc", Arrays.asList(new String[]{"a", "b"}), new HashMap<>()));
20+
21+
Map<String, List<String>> kwargs = new HashMap<>();
22+
kwargs.put("y", Arrays.asList(new String[]{"ka", "kb"}));
23+
Assert.assertEquals("CALL prc(\"a\",\"b\")ka,kb", Utils.prepareProcedure("prc", Arrays.asList(new String[]{"a", "b"}), kwargs));
24+
25+
Assert.assertEquals("CALL prc()ka,kb", Utils.prepareProcedure("prc", Arrays.asList(new String[]{}), kwargs));
26+
}
27+
28+
@Test
29+
public void prepareQuery() {
30+
Assert.assertEquals("query %s %d end of query", Utils.prepareQuery("query %s %d end of query"));
31+
32+
Assert.assertEquals("query 'a' 33 end of query", Utils.prepareQuery("query %s %d end of query", "a", 33));
33+
34+
try {
35+
Assert.assertEquals("CALL prc(\"a\",\"b\")ka,kb", Utils.prepareQuery("query %s %d end of query", "a", "b"));
36+
Assert.fail();
37+
} catch (IllegalFormatConversionException e) {}
38+
}
39+
40+
}

0 commit comments

Comments
 (0)