From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Implement Retrieve Task with Test Driven Development

Implement Retrieve Task with Test Driven Development

From the course: Complete Guide To Java Testing with JUnit 5 & Mockito

Implement Retrieve Task with Test Driven Development

- [Instructor] The last feature we'll add to this application is the ability to retrieve a task. In the Project Requirements we set a task is referenced by its ID, so let's create a test for this in our Task Manager. For the setup, we'll want to add a task to the Task Manager that we can retrieve. Let's create a new taskManager, a new task, and add it to our manager. To retrieve the task, we'll use its ID. This method should return a task. Then in our test, we'll verify it's the same task we added. We could also add assertions that verify the task ID and description if the exact object doesn't need to be equal. Given we're storing the exact object, this assertion covers all of those cases with this single line of code. Now, let's create the method signature for Git. That'll make the test compile. This will return a task and will pass in an ID. By default, it will return null. Let's run our test. Our test fails because we need to implement the get method. For our implementation, we'll…

Contents