Skip to content

Prevent NPE in SessionConfig#equals. #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion driver/src/main/java/org/neo4j/driver/SessionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public boolean equals( Object o )
return false;
}
SessionConfig that = (SessionConfig) o;
return Objects.equals( bookmarks, that.bookmarks ) && defaultAccessMode == that.defaultAccessMode && database.equals( that.database );
return Objects.equals( bookmarks, that.bookmarks ) && defaultAccessMode == that.defaultAccessMode && Objects.equals( database, that.database );
}

@Override
Expand Down
23 changes: 21 additions & 2 deletions driver/src/test/java/org/neo4j/driver/SessionConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
*/
package org.neo4j.driver;

import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import org.neo4j.driver.internal.Bookmark;

Expand All @@ -37,6 +39,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.neo4j.driver.SessionConfig.builder;
import static org.neo4j.driver.SessionConfig.defaultConfig;
import static org.neo4j.driver.internal.InternalBookmark.parse;
Expand All @@ -49,7 +52,7 @@ void shouldReturnDefaultValues() throws Throwable
{
SessionConfig config = defaultConfig();

Assert.assertEquals( AccessMode.WRITE, config.defaultAccessMode() );
assertEquals( AccessMode.WRITE, config.defaultAccessMode() );
assertFalse( config.database().isPresent() );
assertNull( config.bookmarks() );
}
Expand Down Expand Up @@ -77,6 +80,22 @@ void shouldNotAllowNullDatabaseName() throws Throwable
assertThrows( NullPointerException.class, () -> builder().withDatabase( null ) );
}

@ParameterizedTest
@MethodSource("someConfigs")
void nullDatabaseNameMustNotBreakEquals(SessionConfig config1, SessionConfig config2, boolean expectedEquals) {

assertEquals( config1.equals( config2 ), expectedEquals );
}

static Stream<Arguments> someConfigs() {
return Stream.of(
arguments( SessionConfig.builder().build(), SessionConfig.builder().build(), true ),
arguments( SessionConfig.builder().withDatabase( "a" ).build(), SessionConfig.builder().build(), false ),
arguments( SessionConfig.builder().build(), SessionConfig.builder().withDatabase( "a" ).build(), false ),
arguments( SessionConfig.builder().withDatabase( "a" ).build(), SessionConfig.builder().withDatabase( "a" ).build(), true )
);
}

@ParameterizedTest
@ValueSource( strings = {"", ABSENT_DB_NAME} )
void shouldForbiddenEmptyStringDatabaseName( String databaseName ) throws Throwable
Expand Down