Skip to content

[test-improver] Add 29 Mockito unit tests for TaskService#63

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test-assist/taskservice-unit-tests-2749332c8778b42c
Draft

[test-improver] Add 29 Mockito unit tests for TaskService#63
github-actions[bot] wants to merge 1 commit into
mainfrom
test-assist/taskservice-unit-tests-2749332c8778b42c

Conversation

@github-actions

Copy link
Copy Markdown

🤖 Test Improver — automated AI assistant focused on improving tests.

Goal & Rationale

TaskService is the largest and most bug-prone class in the codebase (~700 lines, multiple known bugs), yet it had zero pure unit tests. The existing TaskServiceTest uses @SpringBootTest (full context, H2 DB, DataInitializer seeding) — slow, fragile, and susceptible to ordering issues.

This PR adds 29 pure Mockito unit tests (@ExtendWith(MockitoExtension.class)) that run in under 1 second with no Spring context and no database. These tests are a prerequisite for the planned god-class refactoring tracked in Issue #16.

Approach

  • @InjectMocks TaskService + @Mock for TaskRepository, UserRepository, ProjectRepository
  • Covers: createTask, updateTask, getTask, deleteTask, assignTask, transitionStatus, getTaskStatistics, getAllTasks, getTasksByStatus, getTasksByAssignee
  • 1 bug-pin test documenting the known division-by-zero in getTaskStatistics (Bug 🔴 [BUG] ArithmeticException: Division by zero on empty project dashboard #3)
  • State machine tests for all documented transitionStatus transitions

Coverage Impact

No baseline JaCoCo data available on main branch yet (Issue #47). These tests exercise TaskService methods that were previously only covered through full-context @SpringBootTest.

Bug Pin: getTaskStatistics / Bug #3

// getTaskStatistics_noCompletedTasks_divisionByZeroBug
assertThrows(ArithmeticException.class,
    () -> taskService.getTaskStatistics(), "BUG #3: division by zero when no completed tasks");

This test documents the current broken behaviour. Do NOT modify the test to pass — fix getTaskStatistics() in the production code (guard completedCount == 0), then verify the other getTaskStatistics_withCompletedTasks_returnsCorrectCounts test still passes.

Trade-offs

  • These are unit tests — they mock repositories. Integration behaviour (persistence, transaction boundaries) is not tested here. The existing TaskServiceTest @SpringBootTest tests continue to provide that coverage.
  • sendTaskNotification is a private method that swallows all exceptions; not directly testable with Mockito.

Test Status

Tests run: 29, Failures: 0, Errors: 0, Skipped: 0
Time elapsed: 0.516 s
BUILD SUCCESS

Reproducibility

mvn test -Dtest=TaskServiceMockTest -Dmaven.repo.local=/tmp/m2 -B

Generated by Test Improver · 102.7 AIC · ⌖ 10.5 AIC · ⊞ 10.9K ·
Comment /test-assist to run again

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@1c6668b751c51af8571f01204ceffb19362e0f66

Covers: createTask validation, updateTask, getTask, deleteTask,
assignTask, transitionStatus state machine, getTaskStatistics
(including bug-pin for division-by-zero Bug #3), getAllTasks,
getTasksByStatus, getTasksByAssignee.

All tests run in <1s with no Spring context or DB.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants