[test-improver] Add @WebMvcTest tests for ProjectController (16 tests, 2 bug pins)#54
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
- Tests for all 8 endpoints: GET /api/projects, GET /{id},
GET /code/{code}, POST, PUT /{id}, DELETE /{id},
GET /{id}/dashboard, POST /{id}/members
- Bug-pin: POST /api/projects returns 200 instead of 201 Created
- Bug-pin: GET /{id}/dashboard with taskCount=0 returns NaN in JSON
body (Project.getProgress() returns NaN, which Jackson serializes
as the literal token 'NaN' - not valid JSON)
- Documents getMemberIds() NPE when members is null (test data sets
members to avoid triggering separate bug during serialization)
Tests run: 54 (+16), Failures: 1, Errors: 1, Skipped: 7
Pre-existing failures unchanged (DateUtilsTest#6, TaskServiceTest#3)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jul 7, 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
ProjectControllerhad zero effective test coverage — the HTTP layer was completely untested. This PR adds 16@WebMvcTesttests covering all 8 endpoints and documents two real bugs as bug-pin tests.Approach
Used
@WebMvcTest(ProjectController.class)with@MockBean ProjectRepositoryand@MockBean TaskService. Tests the HTTP layer in isolation (fast, no full Spring context, no database).Tests added
getAllProjects_returnsJsonListGET /api/projectsgetAllProjects_emptyList_returnsEmptyArrayGET /api/projectsgetProject_existingId_returns200WithBodyGET /api/projects/1getProject_missingId_returns404GET /api/projects/9999TaskController.getTask— see PR #52)getProjectByCode_found_returns200GET /api/projects/code/TESTgetProjectByCode_notFound_returns404GET /api/projects/code/NOPEcreateProject_setsStatusZeroAndReturnsBody_BUG_returns200InsteadOf201POST /api/projectsupdateProject_existingId_returns200PUT /api/projects/1updateProject_missingId_returns404PUT /api/projects/9999deleteProject_returns204DELETE /api/projects/1getProjectDashboard_notFound_returns404GET /api/projects/9999/dashboardgetProjectDashboard_found_returns200WithCompositeDataGET /api/projects/1/dashboard{project, tasks, stats, progress}getProjectDashboard_zeroTasks_BUG_progressIsNaNGET /api/projects/2/dashboardNaNaddMember_projectNotFound_returns404POST /api/projects/9999/membersaddMember_emptyMembersList_setsUserIdPOST /api/projects/1/membersmembersset to user IDaddMember_existingMembers_appendsUserId_BUG_noDuplicateCheckPOST /api/projects/1/membersBug-pin tests
1.
POST /api/projectsreturns 200 instead of 201 CreatedProjectController.createProject()usesResponseEntity.ok(saved)— the code even has a comment:"Should be 201 Created". When fixed, changeisOk()toisCreated()in the test.2.
GET /api/projects/{id}/dashboardwithtaskCount=0returnsNaNin JSONProject.getProgress()computes(double)completedTaskCount / taskCount * 100. WhentaskCount=0, Java floating-point division returnsNaN. Jackson 2.13 serializes this as the literal tokenNaNin the response body (not valid JSON — RFC 8259 §6 requires finite numbers). This causes client-side JSON parsers to fail.Fix:
return taskCount == 0 ? 0.0 : (double) completedTaskCount / taskCount * 100;When fixed, replace the
content().string(containsString("NaN"))assertion withjsonPath("$.progress").value(0.0).Note on
getMemberIds()NPE:Project.getMemberIds()throwsNullPointerExceptionwhenmembersis null. Jackson calls all public getters during serialization, so anyGETendpoint returning a project withmembers=nullwould return 500 in production. Test data in this PR setsmembersto a valid value to avoid masking other bugs; this secondary bug is documented in test comments.Coverage Impact
ProjectControllerline coverageTrade-offs
@WebMvcTestkeeps tests fast (~0.7s total run time) with no DB or full context.addMemberduplicate-userId bug is documented in a comment rather than a dedicated test (requires the same request twice — out of scope for controller layer tests).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