Skip to content

[test-improver] Add @DataJpaTest tests for TaskRepository (14 tests, 2 bug-pins)#82

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test-assist/task-repository-tests-52c116aca5201159
Draft

[test-improver] Add @DataJpaTest tests for TaskRepository (14 tests, 2 bug-pins)#82
github-actions[bot] wants to merge 1 commit into
mainfrom
test-assist/task-repository-tests-52c116aca5201159

Conversation

@github-actions

Copy link
Copy Markdown

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

Goal & Rationale

TaskRepository had zero tests despite containing custom JPQL queries with documented bugs. Two queries include FIXME comments stating they should also exclude cancelled tasks (status=3) but don't — this creates silent data integrity issues where cancelled tasks show up as "active".

Key testing opportunities:

  • Bug pin: findActiveTasks() returns cancelled tasks (FIXME in source)
  • Bug pin: findActiveTasksByAssignee() returns cancelled tasks (same root cause)
  • Functional coverage for all 6 custom queries

Approach

Used @DataJpaTest — a Spring slice test that boots only JPA/H2, no web layer. This is ~3× faster than @SpringBootTest and avoids DataInitializer seeding interference. Each test calls taskRepository.deleteAll() in @BeforeEach for full isolation.

Tests added (14 total)

Test What it verifies
findByStatus_returnsOnlyMatchingStatus Only tasks with the queried status are returned
findByStatus_returnsEmptyWhenNoneMatch No results for status with no data
findByAssigneeId_returnsTasksForGivenAssignee Assignee filter via workaround @Query
findByAssigneeId_returnsEmptyForUnknownAssignee Correct empty result
findByProjectCode_returnsTasksForProject Project code filter
findHighPriorityTasks_returnsPriority3AndAbove Priority >= 3 threshold (high/critical/blocker)
findHighPriorityTasks_excludesLowAndMediumPriority Low/medium not included
findActiveTasks_includesTodoAndInProgress Active statuses correctly included
findActiveTasks_excludesDoneTasks Done (status=2) correctly excluded
findActiveTasks_bugPin_cancelledTasksAreIncorrectlyReturned BUG PIN: cancelled tasks returned
findByType_returnsOnlyMatchingType Type filter
findActiveTasksByAssignee_returnsAssigneesNonDoneTasks Assignee + active filter combined
findActiveTasksByAssignee_orderedByPriorityDescending ORDER BY priority DESC verified
findActiveTasksByAssignee_bugPin_cancelledTasksAreIncorrectlyReturned BUG PIN: cancelled tasks returned

Bug Pins

Both findActiveTasks() and findActiveTasksByAssignee() have identical FIXME comments in TaskRepository.java:

// FIXME: This query is wrong - should be status != 2 (done) and status != 3 (cancelled)
`@Query`("SELECT t FROM Task t WHERE t.status != 2")
List<Task> findActiveTasks();

The bug-pin tests document that cancelled tasks (status=3) are currently returned by both methods. When this bug is fixed, these tests will fail — which is the intended signal.

Coverage Impact

@DataJpaTest slice tests instrument the JPA layer only. The TaskRepository interface itself is proxy-generated (no coverage number), but the custom @Query annotations are exercised through integration with H2.

Test Status

Tests run: 14, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Reproducibility

mvn test -Dtest=TaskRepositoryTest -B

Generated by Test Improver · 83.7 AIC · ⌖ 11.6 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

- findByStatus, findByAssigneeId, findByProjectCode, findByType: functional coverage
- findHighPriorityTasks: verifies priority >= 3 threshold
- findActiveTasks + findActiveTasksByAssignee: 2 bug-pin tests documenting
  that cancelled tasks (status=3) are incorrectly returned by both queries
  (FIXME comment in TaskRepository acknowledges the bug)

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