Skip to content

Refactoring #1466

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
Jul 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum Type {
UNSUPPORTED,
PERFORMANCE,
DEPRECATION,
GENERIC;
GENERIC
}

public static Optional<NotificationCategory> valueOf(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static <K, V> Pair<K, V> of(K key, V value) {

@Override
public String toString() {
return String.format("%s: %s", Objects.toString(key), Objects.toString(value));
return String.format("%s: %s", key, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@

import static java.util.concurrent.TimeUnit.SECONDS;

public class RoutingSettings {
public record RoutingSettings(long routingTablePurgeDelayMs, RoutingContext routingContext) {
public static final long STALE_ROUTING_TABLE_PURGE_DELAY_MS = SECONDS.toMillis(30);

private final RoutingContext routingContext;
private final long routingTablePurgeDelayMs;

public RoutingSettings(long routingTablePurgeDelayMs, RoutingContext routingContext) {
this.routingContext = routingContext;
this.routingTablePurgeDelayMs = routingTablePurgeDelayMs;
}

public RoutingContext routingContext() {
return routingContext;
}

public long routingTablePurgeDelayMs() {
return routingTablePurgeDelayMs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ private void packPoint(Point point) throws IOException {
} else if (point instanceof InternalPoint3D) {
packPoint3D(point);
} else {
throw new IOException(
String.format("Unknown type: type: %s, value: %s", point.getClass(), point.toString()));
throw new IOException(String.format("Unknown type: type: %s, value: %s", point.getClass(), point));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.Serial;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -204,7 +205,7 @@ public class PackStream {

private static final String EMPTY_STRING = "";
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final Charset UTF_8 = StandardCharsets.UTF_8;

private PackStream() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static <V> String formatPairs(Map<String, V> entries) {
}

private static <V> String keyValueString(Entry<String, V> entry) {
return String.format("%s: %s", entry.getKey(), String.valueOf(entry.getValue()));
return String.format("%s: %s", entry.getKey(), entry.getValue());
}

/**
Expand Down
27 changes: 11 additions & 16 deletions driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,54 +93,49 @@ void shouldFailToCreateEncryptedDriverWhenServerDoesNotRespond() throws IOExcept

@Test
void shouldAcceptNullTokenOnFactoryWithString() {
AuthToken token = null;
GraphDatabase.driver("neo4j://host", token);
GraphDatabase.driver("neo4j://host", (AuthToken) null);
}

@Test
void shouldAcceptNullTokenOnFactoryWithUri() {
AuthToken token = null;
GraphDatabase.driver(URI.create("neo4j://host"), token);
GraphDatabase.driver(URI.create("neo4j://host"), (AuthToken) null);
}

@Test
void shouldAcceptNullTokenOnFactoryWithStringAndConfig() {
AuthToken token = null;
GraphDatabase.driver("neo4j://host", token, Config.defaultConfig());
GraphDatabase.driver("neo4j://host", (AuthToken) null, Config.defaultConfig());
}

@Test
void shouldAcceptNullTokenOnFactoryWithUriAndConfig() {
AuthToken token = null;
GraphDatabase.driver(URI.create("neo4j://host"), token, Config.defaultConfig());
GraphDatabase.driver(URI.create("neo4j://host"), (AuthToken) null, Config.defaultConfig());
}

@Test
void shouldRejectNullAuthTokenManagerOnFactoryWithString() {
AuthTokenManager manager = null;
assertThrows(NullPointerException.class, () -> GraphDatabase.driver("neo4j://host", manager));
assertThrows(NullPointerException.class, () -> GraphDatabase.driver("neo4j://host", (AuthTokenManager) null));
}

@Test
void shouldRejectNullAuthTokenManagerOnFactoryWithUri() {
AuthTokenManager manager = null;
assertThrows(NullPointerException.class, () -> GraphDatabase.driver(URI.create("neo4j://host"), manager));
assertThrows(
NullPointerException.class,
() -> GraphDatabase.driver(URI.create("neo4j://host"), (AuthTokenManager) null));
}

@Test
void shouldRejectNullAuthTokenManagerOnFactoryWithStringAndConfig() {
AuthTokenManager manager = null;
assertThrows(
NullPointerException.class,
() -> GraphDatabase.driver("neo4j://host", manager, Config.defaultConfig()));
() -> GraphDatabase.driver("neo4j://host", (AuthTokenManager) null, Config.defaultConfig()));
}

@Test
void shouldRejectNullAuthTokenManagerOnFactoryWithUriAndConfig() {
AuthTokenManager manager = null;
assertThrows(
NullPointerException.class,
() -> GraphDatabase.driver(URI.create("neo4j://host"), manager, Config.defaultConfig()));
() -> GraphDatabase.driver(
URI.create("neo4j://host"), (AuthTokenManager) null, Config.defaultConfig()));
}

private static void testFailureWhenServerDoesNotRespond(boolean encrypted) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
package org.neo4j.driver.integration;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.atLeastOnce;
Expand Down Expand Up @@ -328,7 +327,7 @@ void resultRecordsShouldReleaseConnectionUsedBySessionRun() {
.verifyComplete();

var connection2 = connectionPool.lastAcquiredConnectionSpy;
assertNotSame(connection1, connection2);
assertNotNull(connection2);
verify(connection2).release();
}

Expand All @@ -344,7 +343,7 @@ void resultSummaryShouldReleaseConnectionUsedBySessionRun() {
StepVerifier.create(Mono.from(res.consume())).expectNextCount(1).verifyComplete();

var connection2 = connectionPool.lastAcquiredConnectionSpy;
assertNotSame(connection1, connection2);
assertNotNull(connection2);
verify(connection2).release();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ private static void testIllegalUri(URI uri) {
private static void testEmptyRoutingContext(URI uri) {
var context = new RoutingContext(uri);

Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("address", "localhost:7687");

assertFalse(context.isDefined());
assertEquals(singletonMap("address", "localhost:7687"), context.toMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

Expand All @@ -31,11 +32,9 @@
*/
public class StdIOCapture implements AutoCloseable {
private final List<String> stdout = new CopyOnWriteArrayList<>();
private final List<String> stderr = new CopyOnWriteArrayList<>();
private final PrintStream originalStdOut;
private final PrintStream originalStdErr;
private final ByteArrayOutputStream capturedStdOut;
private final ByteArrayOutputStream capturedStdErr;

/** Put this in a try-with-resources block to capture all standard io that happens within the try block */
public static StdIOCapture capture() {
Expand All @@ -46,7 +45,7 @@ private StdIOCapture() {
originalStdOut = System.out;
originalStdErr = System.err;
capturedStdOut = new ByteArrayOutputStream();
capturedStdErr = new ByteArrayOutputStream();
var capturedStdErr = new ByteArrayOutputStream();

System.setOut(new PrintStream(capturedStdOut));
System.setErr(new PrintStream(capturedStdErr));
Expand All @@ -60,7 +59,6 @@ public List<String> stdout() {
public void close() throws UnsupportedEncodingException {
System.setOut(originalStdOut);
System.setErr(originalStdErr);
stdout.addAll(asList(capturedStdOut.toString("UTF-8").split(System.lineSeparator())));
stderr.addAll(asList(capturedStdErr.toString("UTF-8").split(System.lineSeparator())));
stdout.addAll(asList(capturedStdOut.toString(StandardCharsets.UTF_8).split(System.lineSeparator())));
}
}