Skip to content

Commit e3f423a

Browse files
committed
Merge pull request #101 from pontusmelke/null-keys
keys should never return null
2 parents aa3a4d0 + 4f24ee9 commit e3f423a

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

driver/src/main/java/org/neo4j/driver/internal/summary/ResultBuilder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@
3939
import org.neo4j.driver.v1.exceptions.ClientException;
4040

4141
import static java.util.Collections.unmodifiableMap;
42-
4342
import static org.neo4j.driver.internal.ParameterSupport.NO_PARAMETERS;
4443

4544
public class ResultBuilder implements StreamCollector
4645
{
46+
private final static List<String> NO_KEYS = new ArrayList<>();
47+
4748
private final SummaryBuilder summaryBuilder;
4849

4950
private List<Record> body = new ArrayList<>();
50-
private List<String> keys = null;
51-
private Map<String, Integer> keyIndexLookup = null;
51+
private List<String> keys = NO_KEYS;
52+
private Map<String,Integer> keyIndexLookup = null;
5253

5354
public ResultBuilder( String statement, Map<String, Value> parameters )
5455
{
@@ -60,7 +61,7 @@ public ResultBuilder( String statement, Map<String, Value> parameters )
6061
@Override
6162
public void keys( String[] names )
6263
{
63-
if ( keys == null )
64+
if ( keys == NO_KEYS )
6465
{
6566
int numFields = names.length;
6667
if ( numFields == 0 )

driver/src/test/java/org/neo4j/driver/internal/InternalSessionTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,34 @@ public void shouldBeAbleToOpenTxAfterPreviousIsClosed() throws Throwable
7878
// Then we should've gotten a transaction object back
7979
assertNotNull( tx );
8080
}
81+
82+
@Test
83+
public void shouldNotBeAbleToUseSessionWhileOngoingTransaction() throws Throwable
84+
{
85+
// Given
86+
Connection mock = mock( Connection.class );
87+
InternalSession sess = new InternalSession( mock );
88+
sess.beginTransaction();
89+
90+
// Expect
91+
exception.expect( ClientException.class );
92+
93+
// When
94+
sess.run( "whatever" );
95+
}
96+
97+
@Test
98+
public void shouldBeAbleToUseSessionAgainWhenTransactionIsClosed() throws Throwable
99+
{
100+
// Given
101+
Connection mock = mock( Connection.class );
102+
InternalSession sess = new InternalSession( mock );
103+
sess.beginTransaction().close();
104+
105+
// When
106+
sess.run( "whatever" );
107+
108+
// Then
109+
verify( mock ).sync();
110+
}
81111
}

driver/src/test/java/org/neo4j/driver/v1/integration/ResultStreamIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import org.neo4j.driver.v1.util.TestNeo4jSession;
2727

2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertNotNull;
2930
import static org.junit.Assert.assertTrue;
3031
import static org.junit.Assert.fail;
31-
3232
import static org.neo4j.driver.v1.Values.parameters;
3333

3434
public class ResultStreamIT
@@ -109,4 +109,14 @@ public void shouldGiveHelpfulFailureMessageWhenAccessNonExistingPropertyOnNode()
109109
// Then
110110
assertTrue( rs.value( "n" ).value( "age" ).isNull() );
111111
}
112+
113+
@Test
114+
public void shouldNotReturnNullKeysOnEmptyResult()
115+
{
116+
// Given
117+
ResultCursor rs = session.run( "CREATE (n:Person {name:{name}})", parameters( "name", "Tom Hanks" ) );
118+
119+
// THEN
120+
assertNotNull( rs.keys() );
121+
}
112122
}

0 commit comments

Comments
 (0)