After you have finished these exercises, you understand how you can write reusable custom assertions with AssertJ-DB. During these exercises you will write custom assertion methods which ensure that the expected data is found from the todo_item
table. When you are writing these custom assertion methods, you have to use two constants classes which are described in the following.
The constant class which specifies the structure of the todo_item
table looks as follows:
public class TodoItemTable { public static final String COLUMN_NAME_ID = "id"; public static final String COLUMN_NAME_DESCRIPTION = "description"; public static final String COLUMN_NAME_CREATED_BY_USER_ID = "created_by_user_id"; public static final String COLUMN_NAME_CREATION_TIME = "creation_time"; public static final String COLUMN_NAME_MODIFICATION_TIME = "modification_time"; public static final String COLUMN_NAME_MODIFIED_BY_USER_ID = "modified_by_user_id"; public static final String COLUMN_NAME_RESOLUTION = "resolution"; public static final String COLUMN_NAME_STATUS = "status"; public static final String COLUMN_NAME_TITLE = "title"; public static final String COLUMN_NAME_VERSION = "version"; public static final String NAME = "todo_item"; private TodoItemTable() {} }
The constant class that defines the test data which inserted into the todo_item
table looks as follows:
import com.cleantestautomation.assertjdb.TestDateTimeBuilder; import com.cleantestautomation.assertjdb.useraccount.UserAccounts; public class TodoItems { public static final Long DEFAULT_VERSION = 0L; public static final int TODO_ITEM_ROW_COUNT = 2; public static final Long UNKNOWN_ID = 99L; public static class ReadAllLessons { public static final Long ID = 1L; public static final Long CREATED_BY_USER_ID = UserAccounts.AnneOwens.ID; public static final String CREATION_TIME_DB = TestDateTimeBuilder .transformUTCDateTimeToLocalDateTime("2023-07-07T10:46:00"); public static final String DESCRIPTION = "Be diligent"; public static final String UPDATED_DESCRIPTION = "Finish this todo item before the end of this month"; public static final String MODIFICATION_TIME = CREATION_TIME_DB; public static final Long MODIFIED_BY_USER_ID = CREATED_BY_USER_ID; public static final TodoItemResolution NO_RESOLUTION = null; public static final TodoItemStatus STATUS_OPEN = TodoItemStatus.OPEN; public static final String TITLE = "Read all lessons"; public static final String UPDATED_TITLE = "Finish the course"; public static final Long VERSION = 0L; } public static class FinishAllExercises { public static final Long ID = 2L; public static final Long CREATED_BY_USER_ID = UserAccounts.AnneOwens.ID; public static final String CREATION_TIME_DB = TestDateTimeBuilder .transformUTCDateTimeToLocalDateTime("2023-07-07T12:46:00"); public static final String DESCRIPTION = "Do not use copy & paste"; public static final String MODIFICATION_TIME_DB = CREATION_TIME_DB; public static final Long MODIFIED_BY_USER_ID = CREATED_BY_USER_ID; public static final TodoItemResolution NO_RESOLUTION = null; public static final TodoItemStatus STATUS_OPEN = TodoItemStatus.OPEN; public static final String TITLE = "Finish all exercises"; public static final Long VERSION = 0L; } private TodoItems() {} }
Before you can start doing the exercises of this lesson, you have to finish these steps which are the same for all exercises of the Writing Custom Assertions With AssertJ-DB lesson:
1. Clone the Git repository that contains the sample applications of this course. If you have already cloned that repository, you can ignore this step.
2. Open the project found from the introduction-to-assertj-db/writing-assertions-with-assertj-db/writing-custom-assertions directory with your favorite IDE.