Skip to content

Commit c28209e

Browse files
committed
feat: add count query tests for Neo4JQueryBuilder
Implemented unit tests for building count queries with and without conditions in Neo4JQueryBuilder, ensuring correct Cypher query generation and parameter binding for the SelectQuery interface. Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 5e95df3 commit c28209e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

jnosql-neo4j/src/test/java/org/eclipse/jnosql/databases/neo4j/communication/Neo4JQueryBuilderTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,40 @@ void shouldBuildSelectQueryWithoutCondition() {
9292
assertThat(cypher).isEqualTo("MATCH (e:Person) RETURN e.name, e.age");
9393
}
9494

95+
@Test
96+
void shouldBuildCountQueryWithCondition() {
97+
SelectQuery query = mock(SelectQuery.class);
98+
when(query.name()).thenReturn("Person");
99+
100+
CriteriaCondition condition = mock(CriteriaCondition.class);
101+
Element element = mock(Element.class);
102+
when(condition.element()).thenReturn(element);
103+
when(element.name()).thenReturn("age");
104+
when(element.get()).thenReturn(30);
105+
when(condition.condition()).thenReturn(org.eclipse.jnosql.communication.Condition.EQUALS);
106+
when(query.condition()).thenReturn(java.util.Optional.of(condition));
107+
when(query.columns()).thenReturn(List.of());
108+
109+
Map<String, Object> parameters = new HashMap<>();
110+
String cypher = Neo4JQueryBuilder.INSTANCE.buildQuery(query, parameters);
111+
112+
assertThat(cypher).isEqualTo("MATCH (e:Person) WHERE e.age = $age RETURN COUNT(e)");
113+
assertThat(parameters).containsEntry("age", 30);
114+
}
115+
116+
@Test
117+
void shouldBuildCountQueryWithoutCondition() {
118+
SelectQuery query = mock(SelectQuery.class);
119+
when(query.name()).thenReturn("Person");
120+
when(query.condition()).thenReturn(java.util.Optional.empty());
121+
when(query.columns()).thenReturn(List.of());
122+
123+
Map<String, Object> parameters = new HashMap<>();
124+
String cypher = Neo4JQueryBuilder.INSTANCE.buildQuery(query, parameters);
125+
126+
assertThat(cypher).isEqualTo("MATCH (e:Person) RETURN COUNT(e)");
127+
}
128+
95129
@Test
96130
void shouldTranslateIdToElementId() {
97131
SelectQuery query = mock(SelectQuery.class);

0 commit comments

Comments
 (0)