Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gkorland committed Dec 13, 2023
1 parent e06bdac commit 9b1526e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ public String toString() {

@Override
public Iterator<Record> iterator() {
// TODO Auto-generated method stub
return results.iterator();
}
}
10 changes: 4 additions & 6 deletions src/test/java/com/falkordb/GraphAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testCreateNode() {

try {
iterator.next();
Assert.fail();
fail("Expected NoSuchElementException was not thrown.");
} catch (NoSuchElementException ignored) {
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testDeleteNodes() {

Assert.assertNotNull(client.query("CREATE (:person{name:'roi',age:32})"));
Assert.assertNotNull(client.query(
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(a)"));
"MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit') CREATE (a)-[:knows]->(b)"));
deleteResult = client.query("MATCH (a:person) WHERE (a.name = 'roi') DELETE a");

Assert.assertFalse(deleteResult.iterator().hasNext());
Expand Down Expand Up @@ -155,9 +155,8 @@ public void testIndex() {

try {
client.query("CREATE INDEX ON :person(age)");
fail();
fail("Expected Exception was not thrown.");
} catch (Exception e) {
// TODO: handle exception
}

ResultSet deleteExistingIndexResult = client.query("DROP INDEX ON :person(age)");
Expand All @@ -182,7 +181,6 @@ public void testHeader() {
Assert.assertEquals("HeaderImpl{"
+ "schemaTypes=[COLUMN_SCALAR, COLUMN_SCALAR, COLUMN_SCALAR], "
+ "schemaNames=[a, r, a.age]}", header.toString());
// Assert.assertEquals(-1901778507, header.hashCode());

List<String> schemaNames = header.getSchemaNames();

Expand Down Expand Up @@ -934,7 +932,7 @@ public void testSimpleReadOnlyWithTimeOut() {
"WITH 1000000 as n RETURN reduce(f = 1, x IN range(1, n) | f * x) AS result",
1L);

Assert.fail(); // should timeout
fail("Expected Timeout Exception was not thrown.");
} catch (GraphException e) {
Assert.assertTrue(e.getMessage().contains("Query timed out"));
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/falkordb/TransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ public void testMultiExecWithReadOnlyQueries(){
Assert.assertEquals(1, resultSet.getStatistics().nodesCreated());
Assert.assertEquals(1, resultSet.getStatistics().propertiesSet());

// Graph read-only query result
Assert.assertEquals(ResultSetImpl.class, results.get(4).getClass());

// Graph read-only query result
resultSet = (ResultSet) results.get(3);

Assert.assertNotNull(resultSet.getHeader());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/falkordb/graph_entities/PathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PathTest {

private Node buildNode(int id){
Node n = new Node();
n.setId(0);
n.setId(id);
return n;
}

Expand Down
25 changes: 14 additions & 11 deletions src/test/java/com/falkordb/test/utils/PathBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
public final class PathBuilder{
private final List<Node> nodes;
private final List<Edge> edges;
private Class<?> currentAppendClass;
private Class<?> currentAppendClass = Node.class;

public PathBuilder() {
this.nodes = new ArrayList<>(0);
this.edges = new ArrayList<>(0);
currentAppendClass = Node.class;
this(0);
}

public PathBuilder(int nodesCount){
nodes = new ArrayList<>(nodesCount);
edges = new ArrayList<>(nodesCount-1 >= 0 ? nodesCount -1 : 0);
currentAppendClass = Node.class;
this.nodes = new ArrayList<>(nodesCount);
this.edges = new ArrayList<>(nodesCount > 0 ? nodesCount - 1 : 0);
}

public PathBuilder append(Object object){
Class<? extends Object> c = object.getClass();
if(!currentAppendClass.equals(c)) throw new IllegalArgumentException("Path Builder expected " + currentAppendClass.getSimpleName() + " but was " + c.getSimpleName());
if(c.equals(Node.class)) return appendNode((Node)object);
else return appendEdge((Edge)object);
if(!currentAppendClass.equals(c)){
throw new IllegalArgumentException("Path Builder expected " + currentAppendClass.getSimpleName() + " but was " + c.getSimpleName());
}
if(c.equals(Node.class)) {
return appendNode((Node)object);
}
return appendEdge((Edge)object);
}

private PathBuilder appendEdge(Edge edge) {
Expand All @@ -44,7 +45,9 @@ private PathBuilder appendNode(Node node){
}

public Path build(){
if(nodes.size() != edges.size() + 1) throw new IllegalArgumentException("Path builder nodes count should be edge count + 1");
if(nodes.size() != edges.size() + 1){
throw new IllegalArgumentException("Path builder nodes count should be edge count + 1");
}
return new Path(nodes, edges);
}
}

0 comments on commit 9b1526e

Please sign in to comment.