After you have finished this exercise, you understand how you can specify the test data that’s found from a database table by using one table row and one constant class. During this exercise you will write a table row and a constant class which define the test data that’s found from the todo_item table. The SQL script that inserts the test data into the todo_item table looks as follows:
INSERT INTO todo_item (
id,
created_by_user_id,
creation_time,
description,
modification_time,
modified_by_user_id,
resolution,
status,
title,
version
)
VALUES (
1,
1,
'2023-07-07 10:46:00+00',
'Be diligent',
'2023-07-07 10:46:00+00',
2,
null,
'OPEN',
'Read all lessons',
0
);
INSERT INTO todo_item (
id,
created_by_user_id,
creation_time,
description,
modification_time,
modified_by_user_id,
resolution,
status,
title,
version
)
VALUES (
2,
1,
'2023-07-07 12:46:00+00',
'Do not use copy & paste',
'2023-07-07 12:46:00+00',
1,
null,
'OPEN',
'Finish all exercises',
0
);
You can create your table row class by following these steps:
1. Create a new table row class (TodoItemRow) and put the created class to the com.cleantestautomation.assertjdb.todoitem package.
2. Add the required final fields to the created table row class. Remember that these fields contain the expected column values.
3. Write a builder that’s used to build new TodoItemRow objects.
4. Write a private constructor that takes a Builder object as a constructor argument and sets the field values of the fields which contain the expected column values.
5. Add a build() method to your builder class and implement it by returning a TodoItemRow object.
6. Add a static getBuilder() method to your table row class and implement it by returning a new Builder object.
7. Add getter methods to your table row class.
You can create your constant class by following these steps:
1. Open the TodoItems class that’s found from the com.cleantestautomation.assertjdb.todoitem package.
2. Declare the constant that defines the default version (0L) of a new todo item.
3. Declare the constant that defines the expected row count.
4. Declare the constant which contains the TodoItemRow object that specifies the column values of the first database row.
5. Declare the constant which contains the TodoItemRow object that specifies the column values of the second database row.
static transformUTCDateTimeToLocalDateTime() method of the TestDateTimeBuilder class.