29
29
import org .neo4j .driver .v1 .Transaction ;
30
30
import org .neo4j .driver .v1 .TransactionWork ;
31
31
import org .neo4j .driver .v1 .Value ;
32
+ import org .neo4j .driver .v1 .util .StdIOCapture ;
32
33
import org .neo4j .driver .v1 .util .TestNeo4j ;
33
34
34
35
import static java .util .Arrays .asList ;
35
36
import static org .hamcrest .MatcherAssert .assertThat ;
37
+ import static org .hamcrest .Matchers .containsString ;
36
38
import static org .hamcrest .Matchers .equalTo ;
37
39
import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
38
40
import static org .hamcrest .Matchers .instanceOf ;
@@ -164,16 +166,23 @@ public void testShouldRunConfigUnencryptedExample()
164
166
}
165
167
166
168
@ Test
167
- public void testShouldRunCypherErrorExample ()
169
+ public void testShouldRunCypherErrorExample () throws Exception
168
170
{
169
171
// Given
170
172
CypherErrorExample example = new CypherErrorExample (neo4j .uri ().toString (), TestNeo4j .USER , TestNeo4j .PASSWORD );
171
173
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" );
174
179
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
+ " ^" ) ) );
177
186
}
178
187
179
188
@ Test
@@ -187,16 +196,22 @@ public void testShouldRunDriverLifecycleExample()
187
196
}
188
197
189
198
@ Test
190
- public void testShouldRunHelloWorld ()
199
+ public void testShouldRunHelloWorld () throws Exception
191
200
{
192
201
// Given
193
202
HelloWorld greeter = new HelloWorld (neo4j .uri ().toString (), TestNeo4j .USER , TestNeo4j .PASSWORD );
194
203
195
204
// 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
+ }
197
211
198
212
// Then
199
- // TODO
213
+ assertThat ( stdIO .stdout ().size (), equalTo ( 1 ) );
214
+ assertThat ( stdIO .stdout ().get ( 0 ), containsString ( "hello, world" ) );
200
215
}
201
216
202
217
@ Test
0 commit comments