From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Prevent tasks with duplicate IDs
From the course: Complete Guide To Java Testing with JUnit 5 & Mockito
Prevent tasks with duplicate IDs
- [Instructor] One consequence of using a hash table for our task management is that each task id must be unique. Otherwise, tasks might get overwritten when we add them to the hash table. Let's create a test for this case. We'll set up two tasks with the same id. We'll call them task1 and task2. Let's run this test and it passes. Technically, our contains operation uses the task id to check if a given task exists in the hash map, so it does work as expected, but what we really want to verify is that the number of tasks has increased in the task manager. Let's create a method that returns the number of tasks. We'll use the size of the hash map as a way to check how many tasks are in the task manager. Let's add an assertion to our test. We'll assert that there are two tasks in the task manager. Let's run it again. We've entered the red phase. Our test fails. There's only one task in our manager instead of two. To fix this, instead of passing the id to the task constructor, we could…
Contents
-
-
-
-
-
Task manager project prompt1m 17s
-
(Locked)
Set up red phase for Add Task functionality in Test Class3m 3s
-
(Locked)
Implement Get ID in Task Class2m 14s
-
(Locked)
Implement Add Task and enter green phase1m 54s
-
(Locked)
Prevent tasks with duplicate IDs4m 48s
-
(Locked)
Implement Remove Task with Test Driven Development2m 45s
-
(Locked)
Implement task descriptions with Test Driven Development2m 56s
-
(Locked)
Implement Update Description with Test Driven Development2m 1s
-
(Locked)
Implement Retrieve Task with Test Driven Development2m
-
(Locked)
Refactor tests to ensure maintainability6m 44s
-
-
-
-
-
-
-