[test-improver] Add @WebMvcTest tests for TaskController (13 tests, 2 bug pins)#52
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
Tests cover happy paths (GET all, GET by id, POST create, PUT update, DELETE, GET by status, legacy endpoints) and document two HTTP status code bugs as bug-pin tests: - getTask(missing) returns 200 instead of 404 - deleteTask(missing) returns 400 instead of 404 All new tests pass. Pre-existing failures unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Test Improver — automated AI assistant focused on improving tests.
Goal & Rationale
TaskControllerhad zero effective test coverage — the HTTP layer was completely untested, meaning controller-level bugs (wrong status codes, missing null checks, incorrect response formats) could silently persist. This PR adds 13@WebMvcTesttests covering the main endpoints and documents two known HTTP status code bugs as bug-pin tests.Approach
Used
@WebMvcTest(TaskController.class)with@MockBean TaskService— this tests the HTTP layer in isolation (fast, no full Spring context, no database) while controlling the service responses with Mockito. Each test focuses on a specific behaviour that a controller should guarantee.Tests added
getAllTasks_returnsJsonListGET /api/tasksgetAllTasks_emptyList_returnsEmptyArrayGET /api/tasksgetTask_existingId_returns200WithBodyGET /api/tasks/42getTask_missingId_BUG_returns200InsteadOf404GET /api/tasks/9999createTask_validBody_returns201WithCreatedTaskPOST /api/taskscreateTask_serviceThrows_returns400POST /api/tasksupdateTask_existingId_returns200PUT /api/tasks/5deleteTask_existingId_returns204DELETE /api/tasks/1deleteTask_missingId_BUG_returns400InsteadOf404DELETE /api/tasks/9999getTasksByStatus_returns200WithListGET /api/tasks/status/1getLegacyTasks_returnsWrappedResponseGET /api/v1/tasks{success, data, timestamp}envelopegetLegacyTask_found_returnsSuccessTrueGET /api/v1/tasks/5success=true+ task datagetLegacyTask_notFound_returnsSuccessFalseWithErrorGET /api/v1/tasks/99success=false+ error messageBug-pin tests
Two existing controller bugs are now documented in tests:
GET /api/tasks/{id}with missing id — returns200 OKwith null/empty body instead of404 Not Found. The test comment explains the fix (wrap the result inResponseEntity.notFound().build()).DELETE /api/tasks/{id}with missing id — returns400 Bad Requestinstead of404 Not Found. The catch-allResponseEntity.badRequest()for any RuntimeException is the cause.When either bug is fixed, update the corresponding
_BUG_test's expected status code.Coverage Impact
TaskControllerline coverageCoverage tooling is not yet in CI (Issue #47 tracks adding JaCoCo — requires a manual PR for protected files).
Trade-offs
@SpringBootTestused — these are pure HTTP layer tests, ~0.6s total run time.GET /api/stats(division-by-zero, Issue 🔴 [BUG] ArithmeticException: Division by zero on empty project dashboard #3) not tested here; that bug is in the service layer and is tracked separately.Test Status
Pre-existing failures (not caused by this PR):
DateUtilsTest.testGetQuarter— off-by-one bug (Issue 🔴 [BUG] getQuarter() returns 0-3 instead of 1-4 (off-by-one bug) #6)TaskServiceTest.testGetTaskStatistics— division by zero (Issue 🔴 [BUG] ArithmeticException: Division by zero on empty project dashboard #3)Reproducibility
Add this agentic workflows to your repo
To install this agentic workflow, run