Skip to content

Commit 8cc1106

Browse files
author
Zhen
committed
Muted commandline output
1 parent 9995a82 commit 8cc1106

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3131

3232
import static java.util.concurrent.TimeUnit.SECONDS;
33+
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
3334
// end::service-unavailable-import[]
3435

3536
public class ServiceUnavailableExample implements AutoCloseable
@@ -38,7 +39,8 @@ public class ServiceUnavailableExample implements AutoCloseable
3839

3940
public ServiceUnavailableExample(String uri, String user, String password)
4041
{
41-
driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password), Config.build().withMaxTransactionRetryTime(3, SECONDS).toConfig());
42+
driver = GraphDatabase.driver(uri, AuthTokens.basic(user, password), Config.build()
43+
.withMaxTransactionRetryTime(3, SECONDS).withLogging( DEV_NULL_LOGGING ).toConfig());
4244
}
4345

4446
@Override

examples/src/test/java/org/neo4j/docs/driver/ExamplesIT.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
import org.neo4j.driver.v1.Transaction;
3030
import org.neo4j.driver.v1.TransactionWork;
3131
import org.neo4j.driver.v1.Value;
32+
import org.neo4j.driver.v1.util.StdIOCapture;
3233
import org.neo4j.driver.v1.util.TestNeo4j;
3334

3435
import static java.util.Arrays.asList;
3536
import static org.hamcrest.MatcherAssert.assertThat;
37+
import static org.hamcrest.Matchers.containsString;
3638
import static org.hamcrest.Matchers.equalTo;
3739
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
3840
import static org.hamcrest.Matchers.instanceOf;
@@ -164,16 +166,23 @@ public void testShouldRunConfigUnencryptedExample()
164166
}
165167

166168
@Test
167-
public void testShouldRunCypherErrorExample()
169+
public void testShouldRunCypherErrorExample() throws Exception
168170
{
169171
// Given
170172
CypherErrorExample example = new CypherErrorExample(neo4j.uri().toString(), TestNeo4j.USER, TestNeo4j.PASSWORD);
171173

172-
// When
173-
int employeeNumber = example.getEmployeeNumber("Alice");
174+
// When & Then
175+
StdIOCapture stdIO = new StdIOCapture();
176+
try ( AutoCloseable ignored = stdIO.capture() )
177+
{
178+
int employeeNumber = example.getEmployeeNumber( "Alice" );
174179

175-
// Then
176-
assertThat(employeeNumber, equalTo(-1));
180+
assertThat(employeeNumber, equalTo(-1));
181+
}
182+
assertThat( stdIO.stderr(), equalTo( asList(
183+
"Invalid input 'L': expected 't/T' (line 1, column 3 (offset: 2))",
184+
"\"SELECT * FROM Employees WHERE name = $name\"",
185+
" ^" ) ) );
177186
}
178187

179188
@Test
@@ -187,16 +196,22 @@ public void testShouldRunDriverLifecycleExample()
187196
}
188197

189198
@Test
190-
public void testShouldRunHelloWorld()
199+
public void testShouldRunHelloWorld() throws Exception
191200
{
192201
// Given
193202
HelloWorld greeter = new HelloWorld(neo4j.uri().toString(), TestNeo4j.USER, TestNeo4j.PASSWORD);
194203

195204
// When
196-
greeter.printGreeting("hello, world");
205+
StdIOCapture stdIO = new StdIOCapture();
206+
207+
try ( AutoCloseable ignored = stdIO.capture() )
208+
{
209+
greeter.printGreeting("hello, world");
210+
}
197211

198212
// Then
199-
// TODO
213+
assertThat( stdIO.stdout().size(), equalTo( 1 ) );
214+
assertThat( stdIO.stdout().get( 0 ), containsString( "hello, world" ) );
200215
}
201216

202217
@Test

0 commit comments

Comments
 (0)