Skip to content

Commit ff7bf9e

Browse files
authored
Examples for assertj-db 3.0.0 (#64)
1 parent 0868b5d commit ff7bf9e

File tree

6 files changed

+135
-98
lines changed

6 files changed

+135
-98
lines changed

assertions-examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<dependency>
7676
<groupId>org.assertj</groupId>
7777
<artifactId>assertj-db</artifactId>
78-
<version>1.1.1</version>
78+
<version>3.0.0</version>
7979
<scope>test</scope>
8080
</dependency>
8181
<dependency>

assertions-examples/src/test/java/org/assertj/examples/db/AbstractAssertionsExamples.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.sql.Connection;
1616
import java.sql.SQLException;
1717

18+
import org.assertj.db.type.AssertDbConnection;
19+
import org.assertj.db.type.AssertDbConnectionFactory;
1820
import org.h2.jdbcx.JdbcConnectionPool;
1921
import org.junit.jupiter.api.BeforeEach;
2022

@@ -23,10 +25,12 @@
2325
* Init data for assertions examples.
2426
*
2527
* @author Régis Pouiller
28+
* @author Julien Roy
2629
*/
2730
public class AbstractAssertionsExamples {
2831

2932
protected static JdbcConnectionPool dataSource;
33+
protected static AssertDbConnection assertConnection;
3034

3135
private static final String MEMBERS_CREATE_REQUEST = "create table members(id number primary key, name varchar not null, firstname varchar not null, surname varchar, birthdate date, size decimal);";
3236
private static final String[] MEMBERS_INSERT_REQUESTS = {
@@ -58,6 +62,7 @@ public class AbstractAssertionsExamples {
5862
public void setUp() throws SQLException {
5963
if (dataSource == null) {
6064
dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "user", "password");
65+
assertConnection = AssertDbConnectionFactory.of(dataSource).create();
6166
}
6267
else {
6368
Connection conn = dataSource.getConnection();

assertions-examples/src/test/java/org/assertj/examples/db/ChangesAssertionExamples.java

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* {@link Changes} assertions example.
3232
*
3333
* @author Régis Pouiller
34+
* @author Julien Roy
3435
*/
3536
public class ChangesAssertionExamples extends AbstractAssertionsExamples {
3637

@@ -39,7 +40,7 @@ public class ChangesAssertionExamples extends AbstractAssertionsExamples {
3940
*/
4041
@Test
4142
public void basic_changes_assertion_examples() throws SQLException {
42-
Changes changes = new Changes(dataSource);
43+
Changes changes = assertConnection.changes().build();
4344
changes.setStartPointNow();
4445
makeChangesInTheData();
4546
changes.setEndPointNow();
@@ -58,7 +59,7 @@ public void basic_changes_assertion_examples() throws SQLException {
5859
*/
5960
@Test
6061
public void basic_change_assertion_examples() throws SQLException {
61-
Changes changes = new Changes(dataSource);
62+
Changes changes = assertConnection.changes().build();
6263
changes.setStartPointNow();
6364
makeChangesInTheData();
6465
changes.setEndPointNow();
@@ -92,7 +93,7 @@ public void basic_change_assertion_examples() throws SQLException {
9293
*/
9394
@Test
9495
public void basic_row_assertion_examples() throws SQLException, ParseException {
95-
Changes changes = new Changes(dataSource);
96+
Changes changes = assertConnection.changes().build();
9697
changes.setStartPointNow();
9798
makeChangesInTheData();
9899
changes.setEndPointNow();
@@ -128,7 +129,7 @@ public void basic_row_assertion_examples() throws SQLException, ParseException {
128129
*/
129130
@Test
130131
public void basic_column_assertion_examples() throws SQLException {
131-
Changes changes = new Changes(dataSource);
132+
Changes changes = assertConnection.changes().build();
132133
changes.setStartPointNow();
133134
makeChangesInTheData();
134135
changes.setEndPointNow();
@@ -166,7 +167,7 @@ public void basic_column_assertion_examples() throws SQLException {
166167
*/
167168
@Test
168169
public void basic_value_assertion_examples() throws SQLException, ParseException {
169-
Changes changes = new Changes(dataSource);
170+
Changes changes = assertConnection.changes().build();
170171
changes.setStartPointNow();
171172
makeChangesInTheData();
172173
changes.setEndPointNow();
@@ -193,8 +194,7 @@ public void basic_value_assertion_examples() throws SQLException, ParseException
193194
*/
194195
@Test
195196
public void changes_about_table_assertion_examples() throws SQLException {
196-
Table table = new Table(dataSource, "members");
197-
Changes changes = new Changes(table);
197+
Changes changes = assertConnection.changes().table("members").build();
198198
changes.setStartPointNow();
199199
makeChangesInTheData();
200200
changes.setEndPointNow();
@@ -211,8 +211,7 @@ public void changes_about_table_assertion_examples() throws SQLException {
211211
*/
212212
@Test
213213
public void changes_about_request_assertion_examples() throws SQLException {
214-
Request request = new Request(dataSource, "select title from albums");
215-
Changes changes = new Changes(request);
214+
Changes changes = assertConnection.changes().request("select title from albums").build();
216215
changes.setStartPointNow();
217216
makeChangesInTheData();
218217
changes.setEndPointNow();
@@ -227,7 +226,7 @@ public void changes_about_request_assertion_examples() throws SQLException {
227226
*/
228227
@Test
229228
public void changetype_assertion_examples() throws SQLException {
230-
Changes changes = new Changes(dataSource);
229+
Changes changes = assertConnection.changes().build();
231230
changes.setStartPointNow();
232231
makeChangesInTheData();
233232
changes.setEndPointNow();
@@ -243,7 +242,7 @@ public void changetype_assertion_examples() throws SQLException {
243242
*/
244243
@Test
245244
public void datatype_isontable_assertion_examples() throws SQLException {
246-
Changes changes = new Changes(dataSource);
245+
Changes changes = assertConnection.changes().build();
247246
changes.setStartPointNow();
248247
makeChangesInTheData();
249248
changes.setEndPointNow();
@@ -258,9 +257,8 @@ public void datatype_isontable_assertion_examples() throws SQLException {
258257
* This example shows a simple case of test on data type for change on a request.
259258
*/
260259
@Test
261-
public void datatype_isonrequest_assertion_examples() throws SQLException {
262-
Request request = new Request(dataSource, "select title from albums");
263-
Changes changes = new Changes(request);
260+
public void datatype_is_on_request_assertion_examples() throws SQLException {
261+
Changes changes = assertConnection.changes().request("select title from albums").build();
264262
changes.setStartPointNow();
265263
makeChangesInTheData();
266264
changes.setEndPointNow();
@@ -274,7 +272,7 @@ public void datatype_isonrequest_assertion_examples() throws SQLException {
274272
*/
275273
@Test
276274
public void column_equality_assertion_examples() throws SQLException {
277-
Changes changes = new Changes(dataSource);
275+
Changes changes = assertConnection.changes().build();
278276
changes.setStartPointNow();
279277
makeChangesInTheData();
280278
changes.setEndPointNow();
@@ -304,8 +302,8 @@ public void column_equality_assertion_examples() throws SQLException {
304302
*/
305303
@Test
306304
public void changes_number_assertion_examples() throws SQLException {
307-
Changes changesDataSource = new Changes(dataSource).setStartPointNow();
308-
Changes changesRequest = new Changes(new Request(dataSource, "select title from albums"));
305+
Changes changesDataSource = assertConnection.changes().build().setStartPointNow();
306+
Changes changesRequest = assertConnection.changes().request("select title from albums").build();
309307
changesRequest.setStartPointNow();
310308
makeChangesInTheData();
311309
changesDataSource.setEndPointNow();
@@ -320,7 +318,7 @@ public void changes_number_assertion_examples() throws SQLException {
320318
*/
321319
@Test
322320
public void columns_number_assertion_examples() throws SQLException {
323-
Changes changes = new Changes(dataSource).setStartPointNow();
321+
Changes changes = assertConnection.changes().build().setStartPointNow();
324322
makeChangesInTheData();
325323
changes.setEndPointNow();
326324

@@ -339,7 +337,7 @@ public void columns_number_assertion_examples() throws SQLException {
339337
*/
340338
@Test
341339
public void primary_keys_assertion_examples() throws SQLException {
342-
Changes changes = new Changes(dataSource).setStartPointNow();
340+
Changes changes = assertConnection.changes().build().setStartPointNow();
343341
makeChangesInTheData();
344342
changes.setEndPointNow();
345343

@@ -354,7 +352,7 @@ public void primary_keys_assertion_examples() throws SQLException {
354352
*/
355353
@Test
356354
public void modified_columns_assertion_examples() throws SQLException {
357-
Changes changes = new Changes(dataSource).setStartPointNow();
355+
Changes changes = assertConnection.changes().build().setStartPointNow();
358356
makeChangesInTheData();
359357
changes.setEndPointNow();
360358

@@ -378,7 +376,7 @@ public void modified_columns_assertion_examples() throws SQLException {
378376
*/
379377
@Test
380378
public void column_type_assertion_examples() throws SQLException {
381-
Changes changes = new Changes(dataSource);
379+
Changes changes = assertConnection.changes().build();
382380
changes.setStartPointNow();
383381
makeChangesInTheData();
384382
changes.setEndPointNow();
@@ -408,7 +406,7 @@ public void column_type_assertion_examples() throws SQLException {
408406
*/
409407
@Test
410408
public void modified_column_assertion_examples() throws SQLException {
411-
Changes changes = new Changes(dataSource);
409+
Changes changes = assertConnection.changes().build();
412410
changes.setStartPointNow();
413411
makeChangesInTheData();
414412
changes.setEndPointNow();
@@ -442,7 +440,7 @@ public void modified_column_assertion_examples() throws SQLException {
442440
*/
443441
@Test
444442
public void column_name_assertion_examples() throws SQLException {
445-
Changes changes = new Changes(dataSource);
443+
Changes changes = assertConnection.changes().build();
446444
changes.setStartPointNow();
447445
makeChangesInTheData();
448446
changes.setEndPointNow();
@@ -483,7 +481,7 @@ public void column_name_assertion_examples() throws SQLException {
483481
*/
484482
@Test
485483
public void row_existence_assertion_examples() throws SQLException {
486-
Changes changes = new Changes(dataSource).setStartPointNow();
484+
Changes changes = assertConnection.changes().build().setStartPointNow();
487485
makeChangesInTheData();
488486
changes.setEndPointNow();
489487

@@ -504,7 +502,7 @@ public void row_existence_assertion_examples() throws SQLException {
504502
*/
505503
@Test
506504
public void row_equality_assertion_examples() throws SQLException {
507-
Changes changes = new Changes(dataSource).setStartPointNow();
505+
Changes changes = assertConnection.changes().build().setStartPointNow();
508506
makeChangesInTheData();
509507
changes.setEndPointNow();
510508

@@ -523,7 +521,7 @@ public void row_equality_assertion_examples() throws SQLException {
523521
*/
524522
@Test
525523
public void value_equality_assertion_examples() throws SQLException {
526-
Changes changes = new Changes(dataSource).setStartPointNow();
524+
Changes changes = assertConnection.changes().build().setStartPointNow();
527525
makeChangesInTheData();
528526
changes.setEndPointNow();
529527

@@ -601,7 +599,7 @@ public void value_equality_assertion_examples() throws SQLException {
601599
*/
602600
@Test
603601
public void value_non_equality_assertion_examples() throws SQLException {
604-
Changes changes = new Changes(dataSource).setStartPointNow();
602+
Changes changes = assertConnection.changes().build().setStartPointNow();
605603
makeChangesInTheData();
606604
changes.setEndPointNow();
607605

@@ -679,7 +677,7 @@ public void value_non_equality_assertion_examples() throws SQLException {
679677
*/
680678
@Test
681679
public void value_type_assertion_examples() throws SQLException {
682-
Changes changes = new Changes(dataSource).setStartPointNow();
680+
Changes changes = assertConnection.changes().build().setStartPointNow();
683681
makeChangesInTheData();
684682
changes.setEndPointNow();
685683

@@ -757,7 +755,7 @@ public void value_type_assertion_examples() throws SQLException {
757755
*/
758756
@Test
759757
public void value_nullity_assertion_examples() throws SQLException {
760-
Changes changes = new Changes(dataSource).setStartPointNow();
758+
Changes changes = assertConnection.changes().build().setStartPointNow();
761759
makeChangesInTheData();
762760
changes.setEndPointNow();
763761

@@ -842,7 +840,7 @@ public void value_nullity_assertion_examples() throws SQLException {
842840
*/
843841
@Test
844842
public void value_comparison_assertion_examples() throws SQLException {
845-
Changes changes = new Changes(dataSource).setStartPointNow();
843+
Changes changes = assertConnection.changes().build().setStartPointNow();
846844
makeChangesInTheData();
847845
changes.setEndPointNow();
848846

@@ -936,7 +934,7 @@ public void value_comparison_assertion_examples() throws SQLException {
936934
*/
937935
@Test
938936
public void value_chronology_assertion_examples() throws SQLException {
939-
Changes changes = new Changes(dataSource).setStartPointNow();
937+
Changes changes = assertConnection.changes().build().setStartPointNow();
940938
makeChangesInTheData();
941939
changes.setEndPointNow();
942940

assertions-examples/src/test/java/org/assertj/examples/db/NavigationExamples.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* Examples of navigation for a table, a request and changes
2727
*
2828
* @author Régis Pouiller
29-
*
29+
* @author Julien Roy
3030
*/
3131
public class NavigationExamples extends AbstractAssertionsExamples {
3232

@@ -35,7 +35,7 @@ public class NavigationExamples extends AbstractAssertionsExamples {
3535
*/
3636
@Test
3737
public void basic_navigation_examples_for_a_table() {
38-
Table table = new Table(dataSource, "members");
38+
Table table = assertConnection.table("members").build();
3939

4040
assertThat(table)
4141
.row() // First row
@@ -87,7 +87,7 @@ public void basic_navigation_examples_for_a_table() {
8787
*/
8888
@Test
8989
public void basic_navigation_examples_for_a_request() {
90-
Request request = new Request(dataSource, "select * from members");
90+
Request request = assertConnection.request("select * from members").build();
9191

9292
assertThat(request)
9393
.row() // First row
@@ -139,7 +139,7 @@ public void basic_navigation_examples_for_a_request() {
139139
*/
140140
@Test
141141
public void basic_navigation_examples_for_changes() throws SQLException {
142-
Changes changes = new Changes(dataSource);
142+
Changes changes = assertConnection.changes().build();
143143
changes.setStartPointNow(); // Start point (the moment when the changes start to be taken into account)
144144
makeChangesInTheData();
145145
changes.setEndPointNow(); // End point (the moment when the changes stop to be taken into account)

0 commit comments

Comments
 (0)