Common Steps for All Exercises

After you have finished these exercises, you understand how you can enforce business rules with soft assertions. Let’s start by taking a look at the system under test.

If a todo item was closed because it was finished, the closed todo item must fulfill these conditions:

  • The value of the closerId property must identify the person who closed the todo item.
  • Its resolution must be: TodoItemResolution.DONE.
  • Its status must be: TodoItemStatus.CLOSED.

The closeAsDone() method of the TodoItem class makes sure that these business rules are followed when you close a todo item because it was finished. Its source code looks as follows:

public class TodoItem {

    private Long closerId;
    private TodoItemResolution resolution;
    private String title;
    private TodoItemStatus status;

    //Getters and setters are omitted
    
    public void closeAsDone(Long closerId) {
        this.closerId = closerId;
        this.resolution = TodoItemResolution.DONE;
        this.status = TodoItemStatus.CLOSED;
    }
}

During these exercises you will write an unit test for the closeAsDone() method of the TodoItem class. However, before you can write these unit tests, you have to finish these steps which are the same for all exercises of the Writing Soft Assertions With AssertJ 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-junit5/writing-assertions-with-junit5/exercises/write-assertions-for-business-rules-exercise directory with your favorite IDE.

Remember to revert your changes after you have finished an exercise!