Skip to content

Commit c6eb098

Browse files
committed
Enable compilation failures on warnings for examples
1 parent b0d2c93 commit c6eb098

34 files changed

+88
-79
lines changed

driver/src/test/java/org/neo4j/driver/util/StdIOCapture.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,34 @@
2222

2323
import java.io.ByteArrayOutputStream;
2424
import java.io.PrintStream;
25+
import java.io.UnsupportedEncodingException;
2526
import java.util.List;
2627
import java.util.concurrent.CopyOnWriteArrayList;
2728

2829
/**
2930
* Utility that can be used to temporarily capture and store process-wide stdout and stderr output.
3031
*/
31-
public class StdIOCapture {
32+
public class StdIOCapture implements AutoCloseable {
3233
private final List<String> stdout = new CopyOnWriteArrayList<>();
3334
private final List<String> stderr = new CopyOnWriteArrayList<>();
35+
private final PrintStream originalStdOut;
36+
private final PrintStream originalStdErr;
37+
private final ByteArrayOutputStream capturedStdOut;
38+
private final ByteArrayOutputStream capturedStdErr;
3439

3540
/** Put this in a try-with-resources block to capture all standard io that happens within the try block */
36-
public AutoCloseable capture() {
37-
final PrintStream originalStdOut = System.out;
38-
final PrintStream originalStdErr = System.err;
39-
final ByteArrayOutputStream capturedStdOut = new ByteArrayOutputStream();
40-
final ByteArrayOutputStream capturedStdErr = new ByteArrayOutputStream();
41+
public static StdIOCapture capture() {
42+
return new StdIOCapture();
43+
}
44+
45+
private StdIOCapture() {
46+
originalStdOut = System.out;
47+
originalStdErr = System.err;
48+
capturedStdOut = new ByteArrayOutputStream();
49+
capturedStdErr = new ByteArrayOutputStream();
4150

4251
System.setOut(new PrintStream(capturedStdOut));
4352
System.setErr(new PrintStream(capturedStdErr));
44-
45-
return () -> {
46-
System.setOut(originalStdOut);
47-
System.setErr(originalStdErr);
48-
stdout.addAll(asList(capturedStdOut.toString("UTF-8").split(System.lineSeparator())));
49-
stderr.addAll(asList(capturedStdErr.toString("UTF-8").split(System.lineSeparator())));
50-
};
5153
}
5254

5355
public List<String> stdout() {
@@ -57,4 +59,12 @@ public List<String> stdout() {
5759
public List<String> stderr() {
5860
return stderr;
5961
}
62+
63+
@Override
64+
public void close() throws UnsupportedEncodingException {
65+
System.setOut(originalStdOut);
66+
System.setErr(originalStdErr);
67+
stdout.addAll(asList(capturedStdOut.toString("UTF-8").split(System.lineSeparator())));
68+
stderr.addAll(asList(capturedStdErr.toString("UTF-8").split(System.lineSeparator())));
69+
}
6070
}

examples/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@
8282

8383
<build>
8484
<plugins>
85-
<plugin>
86-
<groupId>org.apache.maven.plugins</groupId>
87-
<artifactId>maven-compiler-plugin</artifactId>
88-
<configuration>
89-
<compilerArgs combine.self="override"/>
90-
</configuration>
91-
</plugin>
9285
<plugin>
9386
<groupId>org.apache.maven.plugins</groupId>
9487
<artifactId>maven-javadoc-plugin</artifactId>

examples/src/main/java/org/neo4j/docs/driver/AsyncResultConsumeExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222

2323
import java.util.List;
2424
import java.util.concurrent.CompletionStage;
25-
import org.neo4j.driver.async.AsyncSession;
2625
// end::async-result-consume-import[]
26+
import org.neo4j.driver.async.AsyncSession;
2727

2828
public class AsyncResultConsumeExample extends BaseApplication {
2929
public AsyncResultConsumeExample(String uri, String user, String password) {
3030
super(uri, user, password);
3131
}
3232

33+
@SuppressWarnings("deprecation")
3334
// tag::async-result-consume[]
3435
public CompletionStage<List<String>> getPeople() {
3536

examples/src/main/java/org/neo4j/docs/driver/AsyncRunMultipleTransactionExample.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
// tag::async-result-consume-import[]
2222

2323
import static org.neo4j.driver.Values.parameters;
24-
// end::async-result-consume-import[]
2524

26-
import java.util.Arrays;
2725
import java.util.List;
2826
import java.util.concurrent.CompletableFuture;
2927
import java.util.concurrent.CompletionStage;
@@ -38,6 +36,7 @@ public AsyncRunMultipleTransactionExample(String uri, String user, String passwo
3836
super(uri, user, password);
3937
}
4038

39+
@SuppressWarnings("deprecation")
4140
// tag::async-multiple-tx[]
4241
public CompletionStage<Integer> addEmployees(final String companyName) {
4342
AsyncSession session = driver.asyncSession();
@@ -53,14 +52,13 @@ private static CompletionStage<List<String>> matchPersonNodes(AsyncTransaction t
5352
cursor -> cursor.listAsync(record -> record.get("name").asString()));
5453
}
5554

56-
private static CompletableFuture<Integer> createNodes(
55+
private static CompletionStage<Integer> createNodes(
5756
AsyncTransaction tx, String companyName, List<String> personNames) {
58-
CompletableFuture<Integer>[] nodeCreatedCounts = personNames.stream()
57+
return personNames.stream()
5958
.map(personName -> createNode(tx, companyName, personName))
60-
.toArray(size -> new CompletableFuture[size]);
61-
return CompletableFuture.allOf(nodeCreatedCounts).thenApply(ignored -> Arrays.stream(nodeCreatedCounts)
62-
.map(CompletableFuture::join)
63-
.reduce(0, Integer::sum));
59+
.reduce(
60+
CompletableFuture.completedFuture(0),
61+
(stage1, stage2) -> stage1.thenCombine(stage2, Integer::sum));
6462
}
6563

6664
private static CompletionStage<Integer> createNode(AsyncTransaction tx, String companyName, String personName) {

examples/src/main/java/org/neo4j/docs/driver/AsyncTransactionFunctionExample.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818
*/
1919
package org.neo4j.docs.driver;
2020
// tag::async-transaction-function-import[]
21+
2122
import java.util.Collections;
2223
import java.util.Map;
2324
import java.util.concurrent.CompletionStage;
25+
// end::async-transaction-function-import[]
2426
import org.neo4j.driver.async.AsyncSession;
2527
import org.neo4j.driver.summary.ResultSummary;
26-
// end::async-transaction-function-import[]
2728

2829
public class AsyncTransactionFunctionExample extends BaseApplication {
2930
public AsyncTransactionFunctionExample(String uri, String user, String password) {
3031
super(uri, user, password);
3132
}
3233

34+
@SuppressWarnings("deprecation")
3335
// tag::async-transaction-function[]
3436
public CompletionStage<ResultSummary> printAllProducts() {
3537
String query = "MATCH (p:Product) WHERE p.id = $id RETURN p.title";

examples/src/main/java/org/neo4j/docs/driver/BaseApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public BaseApplication(String uri, String user, String password) {
3030
}
3131

3232
@Override
33-
public void close() throws Exception {
33+
public void close() throws RuntimeException {
3434
driver.close();
3535
}
3636
}

examples/src/main/java/org/neo4j/docs/driver/BasicAuthExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public BasicAuthExample(String uri, String user, String password) {
3636
// end::basic-auth[]
3737

3838
@Override
39-
public void close() throws Exception {
39+
public void close() throws RuntimeException {
4040
driver.close();
4141
}
4242

examples/src/main/java/org/neo4j/docs/driver/BearerAuthExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public BearerAuthExample(String uri, String bearerToken) {
3535
// end::bearer-auth[]
3636

3737
@Override
38-
public void close() throws Exception {
38+
public void close() throws RuntimeException {
3939
driver.close();
4040
}
4141
}

examples/src/main/java/org/neo4j/docs/driver/ConfigConnectionPoolExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919
package org.neo4j.docs.driver;
2020
// tag::config-connection-pool-import[]
21+
2122
import java.util.concurrent.TimeUnit;
23+
// end::config-connection-pool-import[]
2224
import org.neo4j.driver.AuthTokens;
2325
import org.neo4j.driver.Config;
2426
import org.neo4j.driver.Driver;
2527
import org.neo4j.driver.GraphDatabase;
2628
import org.neo4j.driver.Result;
27-
// end::config-connection-pool-import[]
2829

2930
public class ConfigConnectionPoolExample implements AutoCloseable {
3031
private final Driver driver;
@@ -42,7 +43,7 @@ public ConfigConnectionPoolExample(String uri, String user, String password) {
4243
// end::config-connection-pool[]
4344

4445
@Override
45-
public void close() throws Exception {
46+
public void close() throws RuntimeException {
4647
driver.close();
4748
}
4849

examples/src/main/java/org/neo4j/docs/driver/ConfigConnectionTimeoutExample.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// tag::config-connection-timeout-import[]
2222

2323
import static java.util.concurrent.TimeUnit.SECONDS;
24-
// end::config-connection-timeout-import[]
2524

2625
import org.neo4j.driver.AuthTokens;
2726
import org.neo4j.driver.Config;
@@ -40,7 +39,7 @@ public ConfigConnectionTimeoutExample(String uri, String user, String password)
4039
// end::config-connection-timeout[]
4140

4241
@Override
43-
public void close() throws Exception {
42+
public void close() throws RuntimeException {
4443
driver.close();
4544
}
4645
}

examples/src/main/java/org/neo4j/docs/driver/ConfigCustomResolverExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void addPerson(String name) {
7575
// end::config-custom-resolver[]
7676

7777
@Override
78-
public void close() throws Exception {
78+
public void close() throws RuntimeException {
7979
driver.close();
8080
}
8181

examples/src/main/java/org/neo4j/docs/driver/ConfigMaxRetryTimeExample.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// tag::config-max-retry-time-import[]
2222

2323
import static java.util.concurrent.TimeUnit.SECONDS;
24-
// end::config-max-retry-time-import[]
2524

2625
import org.neo4j.driver.AuthTokens;
2726
import org.neo4j.driver.Config;
@@ -41,7 +40,7 @@ public ConfigMaxRetryTimeExample(String uri, String user, String password) {
4140
// end::config-max-retry-time[]
4241

4342
@Override
44-
public void close() throws Exception {
43+
public void close() throws RuntimeException {
4544
driver.close();
4645
}
4746
}

examples/src/main/java/org/neo4j/docs/driver/ConfigTrustExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ConfigTrustExample(String uri, String user, String password) {
4040
// end::config-trust[]
4141

4242
@Override
43-
public void close() throws Exception {
43+
public void close() throws RuntimeException {
4444
driver.close();
4545
}
4646
}

examples/src/main/java/org/neo4j/docs/driver/ConfigUnencryptedExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ConfigUnencryptedExample(String uri, String user, String password) {
3838
// end::config-unencrypted[]
3939

4040
@Override
41-
public void close() throws Exception {
41+
public void close() throws RuntimeException {
4242
driver.close();
4343
}
4444
}

examples/src/main/java/org/neo4j/docs/driver/CustomAuthExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
// tag::custom-auth-import[]
2222

2323
import java.util.Map;
24+
// end::custom-auth-import[]
2425
import org.neo4j.driver.AuthTokens;
2526
import org.neo4j.driver.Driver;
2627
import org.neo4j.driver.GraphDatabase;
27-
// end::custom-auth-import[]
2828

2929
public class CustomAuthExample implements AutoCloseable {
3030
private final Driver driver;
@@ -42,7 +42,7 @@ public CustomAuthExample(
4242
// end::custom-auth[]
4343

4444
@Override
45-
public void close() throws Exception {
45+
public void close() throws RuntimeException {
4646
driver.close();
4747
}
4848
}

examples/src/main/java/org/neo4j/docs/driver/CypherErrorExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// tag::cypher-error-import[]
2222

2323
import static org.neo4j.driver.Values.parameters;
24-
// end::cypher-error-import[]
2524

2625
import org.neo4j.driver.Result;
2726
import org.neo4j.driver.Session;
@@ -34,6 +33,7 @@ public CypherErrorExample(String uri, String user, String password) {
3433
super(uri, user, password);
3534
}
3635

36+
@SuppressWarnings("deprecation")
3737
// tag::cypher-error[]
3838
public int getEmployeeNumber(final String name) {
3939
try (Session session = driver.session()) {

examples/src/main/java/org/neo4j/docs/driver/DriverIntroductionExample.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import java.util.logging.Level;
2727
import java.util.logging.Logger;
28+
// end::driver-introduction-example-import[]
2829
import org.neo4j.driver.AuthTokens;
2930
import org.neo4j.driver.Config;
3031
import org.neo4j.driver.Driver;
@@ -34,7 +35,6 @@
3435
import org.neo4j.driver.Result;
3536
import org.neo4j.driver.Session;
3637
import org.neo4j.driver.exceptions.Neo4jException;
37-
// end::driver-introduction-example-import[]
3838

3939
// tag::driver-introduction-example[]
4040
public class DriverIntroductionExample implements AutoCloseable {
@@ -47,11 +47,12 @@ public DriverIntroductionExample(String uri, String user, String password, Confi
4747
}
4848

4949
@Override
50-
public void close() throws Exception {
50+
public void close() throws RuntimeException {
5151
// The driver object should be closed before the application ends.
5252
driver.close();
5353
}
5454

55+
@SuppressWarnings("deprecation")
5556
public void createFriendship(final String person1Name, final String person2Name, final String knowsFrom) {
5657
// To learn more about the Cypher syntax, see https://neo4j.com/docs/cypher-manual/current/
5758
// The Reference Card is also a good resource for keywords https://neo4j.com/docs/cypher-refcard/current/
@@ -83,6 +84,7 @@ public void createFriendship(final String person1Name, final String person2Name,
8384
}
8485
}
8586

87+
@SuppressWarnings("deprecation")
8688
public void findPerson(final String personName) {
8789
String readPersonByNameQuery = "MATCH (p:Person)\n" + "WHERE p.name = $person_name\n" + "RETURN p.name AS name";
8890

examples/src/main/java/org/neo4j/docs/driver/DriverLifecycleExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public DriverLifecycleExample(String uri, String user, String password) {
3434
}
3535

3636
@Override
37-
public void close() throws Exception {
37+
public void close() throws RuntimeException {
3838
driver.close();
3939
}
4040
}

examples/src/main/java/org/neo4j/docs/driver/HelloWorldExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// tag::hello-world-import[]
2222

2323
import static org.neo4j.driver.Values.parameters;
24-
// end::hello-world-import[]
2524

2625
import org.neo4j.driver.AuthTokens;
2726
import org.neo4j.driver.Driver;
@@ -38,10 +37,11 @@ public HelloWorldExample(String uri, String user, String password) {
3837
}
3938

4039
@Override
41-
public void close() throws Exception {
40+
public void close() throws RuntimeException {
4241
driver.close();
4342
}
4443

44+
@SuppressWarnings("deprecation")
4545
public void printGreeting(final String message) {
4646
try (Session session = driver.session()) {
4747
String greeting = session.writeTransaction(tx -> {

examples/src/main/java/org/neo4j/docs/driver/KerberosAuthExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public KerberosAuthExample(String uri, String ticket) {
3535
// end::kerberos-auth[]
3636

3737
@Override
38-
public void close() throws Exception {
38+
public void close() throws RuntimeException {
3939
driver.close();
4040
}
4141
}

examples/src/main/java/org/neo4j/docs/driver/PassBookmarkExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import static org.neo4j.driver.SessionConfig.builder;
2424
import static org.neo4j.driver.Values.parameters;
25-
// end::pass-bookmarks-import[]
2625

2726
import java.util.ArrayList;
2827
import java.util.List;
@@ -79,6 +78,7 @@ private Result printFriends(final Transaction tx) {
7978
return result;
8079
}
8180

81+
@SuppressWarnings("deprecation")
8282
public void addEmployAndMakeFriends() {
8383
// To collect the session bookmarks
8484
List<Bookmark> savedBookmarks = new ArrayList<>();

0 commit comments

Comments
 (0)