Skip to content

Commit b37a8b4

Browse files
committed
Dispatch empty query to server
This update ensures that empty query gets dispatched to server and expects it to handle it accordingly. Please note that empty query string will no longer produce `IllegalArgumentException`. Instead, its handling will be defined by server that might produce `ClientException`.
1 parent df8b781 commit b37a8b4

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

driver/src/main/java/org/neo4j/driver/Query.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import org.neo4j.driver.util.Immutable;
2626

2727
import static java.lang.String.format;
28-
import static org.neo4j.driver.internal.util.Iterables.newHashMapWithSize;
29-
import static org.neo4j.driver.internal.util.Preconditions.checkArgument;
3028
import static org.neo4j.driver.Values.ofValue;
3129
import static org.neo4j.driver.Values.value;
30+
import static org.neo4j.driver.internal.util.Iterables.newHashMapWithSize;
31+
import static org.neo4j.driver.internal.util.Preconditions.checkArgument;
3232

3333
/**
3434
* The components of a Cypher query, containing the query text and parameter map.
@@ -201,7 +201,6 @@ public String toString()
201201
private static String validateQueryText(String query )
202202
{
203203
checkArgument( query != null, "Cypher query text should not be null" );
204-
checkArgument( !query.isEmpty(), "Cypher query text should not be an empty string" );
205204
return query;
206205
}
207206
}

driver/src/test/java/org/neo4j/driver/QueryTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import static org.hamcrest.Matchers.equalTo;
2727
import static org.hamcrest.junit.MatcherAssert.assertThat;
28+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2829
import static org.junit.jupiter.api.Assertions.assertThrows;
2930
import static org.neo4j.driver.Values.parameters;
3031

@@ -121,8 +122,12 @@ void shouldProhibitNullQuery()
121122
}
122123

123124
@Test
124-
void shouldProhibitEmptyQuery()
125+
void shouldAcceptEmptyQuery()
125126
{
126-
assertThrows( IllegalArgumentException.class, () -> new Query( "" ) );
127+
// when
128+
Query query = new Query( "" );
129+
130+
// then
131+
assertNotNull( query );
127132
}
128133
}

driver/src/test/java/org/neo4j/driver/integration/QueryIT.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
*/
1919
package org.neo4j.driver.integration;
2020

21-
import org.junit.jupiter.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322
import org.junit.jupiter.api.extension.RegisterExtension;
24-
import org.junit.jupiter.api.function.Executable;
2523

26-
import java.io.PrintWriter;
27-
import java.io.StringWriter;
2824
import java.util.Collections;
2925
import java.util.Iterator;
3026
import java.util.List;
@@ -34,13 +30,13 @@
3430
import org.neo4j.driver.Result;
3531
import org.neo4j.driver.Value;
3632
import org.neo4j.driver.Values;
33+
import org.neo4j.driver.exceptions.ClientException;
3734
import org.neo4j.driver.util.ParallelizableIT;
3835
import org.neo4j.driver.util.SessionExtension;
3936

4037
import static java.util.Arrays.asList;
4138
import static org.hamcrest.CoreMatchers.equalTo;
4239
import static org.hamcrest.MatcherAssert.assertThat;
43-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4440
import static org.junit.jupiter.api.Assertions.assertThrows;
4541
import static org.neo4j.driver.Values.parameters;
4642
import static org.neo4j.driver.util.TestUtil.assertNoCircularReferences;
@@ -186,7 +182,7 @@ void shouldRunSimpleQuery()
186182
void shouldFailForIllegalQueries()
187183
{
188184
assertThrows( IllegalArgumentException.class, () -> session.run( (String) null ) );
189-
assertThrows( IllegalArgumentException.class, () -> session.run( "" ) );
185+
assertThrows( ClientException.class, () -> session.run( "" ) );
190186
}
191187

192188
@Test

0 commit comments

Comments
 (0)