Skip to content

Commit 53a29e3

Browse files
authored
Refactoring (#1477)
1 parent 1a7f23a commit 53a29e3

File tree

12 files changed

+39
-32
lines changed

12 files changed

+39
-32
lines changed

driver/pom.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
<groupId>org.junit.jupiter</groupId>
8080
<artifactId>junit-jupiter</artifactId>
8181
</dependency>
82-
<dependency>
83-
<groupId>org.junit.support</groupId>
84-
<artifactId>testng-engine</artifactId>
85-
</dependency>
8682
<dependency>
8783
<groupId>org.rauschig</groupId>
8884
<artifactId>jarchivelib</artifactId>
@@ -263,6 +259,18 @@
263259
<plugin>
264260
<groupId>org.apache.maven.plugins</groupId>
265261
<artifactId>maven-failsafe-plugin</artifactId>
262+
<dependencies>
263+
<dependency>
264+
<groupId>org.apache.maven.surefire</groupId>
265+
<artifactId>surefire-junit-platform</artifactId>
266+
<version>${surefire.and.failsafe.version}</version>
267+
</dependency>
268+
<dependency>
269+
<groupId>org.apache.maven.surefire</groupId>
270+
<artifactId>surefire-testng</artifactId>
271+
<version>${surefire.and.failsafe.version}</version>
272+
</dependency>
273+
</dependencies>
266274
</plugin>
267275
</plugins>
268276
</build>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public static Value parameters(Object... keysAndValues) {
610610
* @return a function that returns the value passed into it - the identity function
611611
*/
612612
public static Function<Value, Value> ofValue() {
613-
return val -> val;
613+
return Function.identity();
614614
}
615615

616616
/**

driver/src/main/java/org/neo4j/driver/internal/async/NetworkSession.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.concurrent.CompletionStage;
3131
import java.util.concurrent.atomic.AtomicBoolean;
3232
import java.util.concurrent.atomic.AtomicReference;
33+
import java.util.function.Function;
3334
import org.neo4j.driver.AccessMode;
3435
import org.neo4j.driver.AuthToken;
3536
import org.neo4j.driver.Bookmark;
@@ -112,7 +113,7 @@ public CompletionStage<ResultCursor> runAsync(Query query, TransactionConfig con
112113
resultCursorStage = newResultCursorStage.exceptionally(error -> null);
113114
return newResultCursorStage
114115
.thenCompose(AsyncResultCursor::mapSuccessfulRunCompletionAsync)
115-
.thenApply(cursor -> cursor); // convert the return type
116+
.thenApply(Function.identity()); // convert the return type
116117
}
117118

118119
public CompletionStage<RxResultCursor> runRx(
@@ -320,7 +321,7 @@ private CompletionStage<Throwable> closeTransactionAndReleaseConnection() {
320321
// there exists an open transaction, let's close it and propagate the error, if any
321322
return tx.closeAsync()
322323
.thenApply(ignore -> (Throwable) null)
323-
.exceptionally(error -> error);
324+
.exceptionally(Function.identity());
324325
}
325326
// no open transaction so nothing to close
326327
return completedWithNull();

driver/src/main/java/org/neo4j/driver/internal/async/UnmanagedTransaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public CompletionStage<ResultCursor> runAsync(Query query) {
169169
resultCursors.add(cursorStage);
170170
return cursorStage
171171
.thenCompose(AsyncResultCursor::mapSuccessfulRunCompletionAsync)
172-
.thenApply(cursor -> cursor);
172+
.thenApply(Function.identity());
173173
}
174174

175175
public CompletionStage<RxResultCursor> runRx(Query query) {

driver/src/main/java/org/neo4j/driver/internal/reactive/AbstractReactiveSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private CompletionStage<RxResultCursor> runAsStage(
202202
}
203203
}
204204
})
205-
.thenCompose(stage -> stage);
205+
.thenCompose(Function.identity());
206206
}
207207

208208
private <T> CompletionStage<T> releaseConnectionAndRethrow(Throwable throwable) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.neo4j.driver.testutil.TestUtil.await;
2424

2525
import java.util.concurrent.ExecutorService;
26+
import java.util.function.Function;
2627
import org.junit.jupiter.api.AfterEach;
2728
import org.junit.jupiter.api.Test;
2829
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -67,7 +68,7 @@ void shouldErrorToAccessRecordsAfterConsume() {
6768
assertThrows(ResultConsumedException.class, result::peek);
6869
assertThrows(ResultConsumedException.class, () -> result.stream().toArray());
6970
assertThrows(ResultConsumedException.class, () -> result.forEachRemaining(record -> {}));
70-
assertThrows(ResultConsumedException.class, () -> result.list(record -> record));
71+
assertThrows(ResultConsumedException.class, () -> result.list(Function.identity()));
7172
}
7273

7374
@Test
@@ -88,7 +89,7 @@ void shouldErrorToAccessRecordsAfterClose() {
8889
assertThrows(ResultConsumedException.class, result::peek);
8990
assertThrows(ResultConsumedException.class, () -> result.stream().toArray());
9091
assertThrows(ResultConsumedException.class, () -> result.forEachRemaining(record -> {}));
91-
assertThrows(ResultConsumedException.class, () -> result.list(record -> record));
92+
assertThrows(ResultConsumedException.class, () -> result.list(Function.identity()));
9293
}
9394

9495
@Test
@@ -145,7 +146,7 @@ void shouldErrorToAccessRecordsAfterConsumeAsync() {
145146
assertThrows(ResultConsumedException.class, () -> await(result.singleAsync()));
146147
assertThrows(ResultConsumedException.class, () -> await(result.forEachAsync(record -> {})));
147148
assertThrows(ResultConsumedException.class, () -> await(result.listAsync()));
148-
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(record -> record)));
149+
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(Function.identity())));
149150
}
150151

151152
@Test
@@ -164,7 +165,7 @@ void shouldErrorToAccessRecordsAfterCloseAsync() {
164165
assertThrows(ResultConsumedException.class, () -> await(result.singleAsync()));
165166
assertThrows(ResultConsumedException.class, () -> await(result.forEachAsync(record -> {})));
166167
assertThrows(ResultConsumedException.class, () -> await(result.listAsync()));
167-
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(record -> record)));
168+
assertThrows(ResultConsumedException.class, () -> await(result.listAsync(Function.identity())));
168169
}
169170

170171
@Test

driver/src/test/java/org/neo4j/driver/integration/reactive/ReactiveSessionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void onComplete() {
127127
return subscription;
128128
});
129129
}))
130-
.map(future -> future.thenCompose(itself -> itself))
130+
.map(future -> future.thenCompose(Function.identity()))
131131
.toArray(CompletableFuture[]::new);
132132

133133
CompletableFuture.allOf(subscriptionFutures).join();

driver/src/test/java/org/neo4j/driver/integration/reactive/ReactiveStreamsSessionIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected void hookOnNext(@NonNull ReactiveResult result) {
117117
return subscription;
118118
});
119119
}))
120-
.map(future -> future.thenCompose(itself -> itself))
120+
.map(future -> future.thenCompose(Function.identity()))
121121
.toArray(CompletableFuture[]::new);
122122

123123
CompletableFuture.allOf(subscriptionFutures).join();

driver/src/test/java/org/neo4j/driver/internal/cursor/DisposableAsyncResultCursorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import static org.neo4j.driver.testutil.TestUtil.await;
3131

3232
import java.util.concurrent.CompletableFuture;
33+
import java.util.function.Function;
3334
import org.junit.jupiter.api.BeforeEach;
3435
import org.junit.jupiter.api.Test;
3536
import org.neo4j.driver.internal.util.Futures;
@@ -84,7 +85,7 @@ void shouldNotDisposeCursor() {
8485
await(cursor.singleAsync());
8586
await(cursor.forEachAsync(record -> {}));
8687
await(cursor.listAsync());
87-
await(cursor.listAsync(record -> record));
88+
await(cursor.listAsync(Function.identity()));
8889
await(cursor.pullAllFailureAsync());
8990

9091
// Then

driver/src/test/java/org/neo4j/driver/internal/packstream/PackStreamTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.ArrayList;
3535
import java.util.HashMap;
3636
import java.util.Map;
37+
import java.util.function.Function;
3738
import java.util.stream.Collectors;
3839
import java.util.stream.IntStream;
3940
import org.junit.jupiter.api.Test;
@@ -701,7 +702,7 @@ private void assertMap(int size) throws Throwable {
701702
var packer = machine.packer();
702703
var map = IntStream.range(0, size)
703704
.boxed()
704-
.collect(Collectors.toMap(i -> Integer.toString(i), i -> i, (a, b) -> b, HashMap::new));
705+
.collect(Collectors.toMap(i -> Integer.toString(i), Function.identity(), (a, b) -> b, HashMap::new));
705706
packer.pack(map);
706707

707708
// Then

driver/src/test/java/org/neo4j/driver/stress/AbstractStressTestBase.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ private static Bookmark createNodesAsync(int batchCount, Driver driver) throws T
497497
writeTransactions = writeTransactions.thenCompose(ignore -> session.writeTransactionAsync(
498498
tx -> createNodesInTxAsync(tx, batchIndex, AbstractStressTestBase.BIG_DATA_TEST_BATCH_SIZE)));
499499
}
500-
writeTransactions =
501-
writeTransactions.exceptionally(error -> error).thenCompose(error -> safeCloseSession(session, error));
500+
writeTransactions = writeTransactions
501+
.exceptionally(Function.identity())
502+
.thenCompose(error -> safeCloseSession(session, error));
502503

503504
var error = Futures.blockingGet(writeTransactions);
504505
if (error != null) {
@@ -532,7 +533,7 @@ private static void readNodesAsync(Driver driver, Bookmark bookmark) throws Thro
532533
verifyNodeProperties(node);
533534
})))
534535
.thenApply(summary -> (Throwable) null)
535-
.exceptionally(error -> error)
536+
.exceptionally(Function.identity())
536537
.thenCompose(error -> safeCloseSession(session, error));
537538

538539
var error = Futures.blockingGet(readQuery);
@@ -628,7 +629,7 @@ private static CompletionStage<Throwable> createNodesInTxAsync(
628629

629630
return CompletableFuture.allOf(queryFutures)
630631
.thenApply(ignored -> (Throwable) null)
631-
.exceptionally(error -> error);
632+
.exceptionally(Function.identity());
632633
}
633634

634635
private static CompletableFuture<Void> createNodeInTxAsync(AsyncTransaction tx, int nodeIndex) {

pom.xml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
<hamcrest.version>2.2</hamcrest.version>
4646
<mockito-core.version>5.4.0</mockito-core.version>
4747
<junit.version>5.10.0</junit.version>
48-
<testng-engine.version>1.0.4</testng-engine.version>
48+
<!-- supply a newer version than the one supplied by the reactive-streams 1.0.4 -->
49+
<testng.version>7.8.0</testng.version>
4950
<jarchivelib.version>1.2.0</jarchivelib.version>
5051
<bouncycastle-jdk15on.version>1.70</bouncycastle-jdk15on.version>
5152
<logback-classic.version>1.2.12</logback-classic.version>
@@ -153,16 +154,9 @@
153154
<scope>test</scope>
154155
</dependency>
155156
<dependency>
156-
<groupId>org.junit.support</groupId>
157-
<artifactId>testng-engine</artifactId>
158-
<version>${testng-engine.version}</version>
159-
<exclusions>
160-
<exclusion>
161-
<!-- Use the version supplied by the org.junit.jupiter:junit-jupiter -->
162-
<groupId>org.junit.platform</groupId>
163-
<artifactId>junit-platform-engine</artifactId>
164-
</exclusion>
165-
</exclusions>
157+
<groupId>org.testng</groupId>
158+
<artifactId>testng</artifactId>
159+
<version>${testng.version}</version>
166160
<scope>test</scope>
167161
</dependency>
168162
<dependency>

0 commit comments

Comments
 (0)