[test-improver] Add model unit tests: User.getDisplayName() logic and Task.toString() NPE bugs#74
Draft
github-actions[bot] wants to merge 1 commit into
Draft
Conversation
…g() bugs UserModelTest (10 tests): - 3 happy-path tests for all getDisplayName() branches - 3 bug-pin tests: partial name (firstName but no lastName, or vice versa) is silently ignored — caller's name data is lost, method falls back to full_name/username without warning - 2 precedence tests (firstName+lastName beats full_name; full_name beats username) - 2 edge cases (empty strings, default constructor returns null without NPE) TaskModelTest (7 tests): - 2 constructor tests (short and default constructors) - 3 bug-pin tests: Task.toString() throws NPE when assignee_id or due_date is null (calls assignee_id.toString() and due_date.trim() without null checks) - 1 positive test: toString() succeeds when all required fields are set - 1 test: attachmentUrls initialised as empty list (not null) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
15 tasks
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
Two model classes had untested logic with real bugs:
User.getDisplayName()— a 3-branch method with surprising partial-name behaviour: iffirstNameis set butlastNameis null (or vice versa), the set name is silently discarded and the method falls back tofull_name/username. A caller who setsfirstNamebut forgetslastNamegets no error; their data is lost.Task.toString()— two documented NPEs:assignee_id.toString()(line 122) anddue_date.trim()(line 123) both dereference fields without null checks. AnyTaskconstructed via the no-arg JPA constructor will throw whentoString()is called (logging, debugger, etc.).Approach
Pure no-Spring JUnit 5 tests (
@ExtendWith(MockitoExtension.class)not even needed — plain POJO construction). Runs in < 1 s with no context startup.UserModelTest (10 tests):
getDisplayName_bothFirstAndLastName_returnsCombinedgetDisplayName_noFirstOrLastName_usesFullNamegetDisplayName_noNamesAtAll_usesUsernamegetDisplayName_firstNameSetButLastNameNull_fallsBackToFullNamegetDisplayName_firstNameSetLastNameNullNoFullName_fallsBackToUsernamegetDisplayName_lastNameSetButFirstNameNull_fallsBackToUsernamegetDisplayName_firstAndLastNamePrecedeFullNamegetDisplayName_fullNamePrecedesUsernamegetDisplayName_emptyFirstAndLastName_returnsSpaceSeparatedgetDisplayName_defaultConstructor_noNPETaskModelTest (7 tests):
shortConstructor_setsFieldsCorrectlydefaultConstructor_allFieldsDefaultToNulltoString_nullAssigneeId_throwsNPEtoString_nullDueDate_throwsNPEtoString_defaultConstructorFields_throwsNPEtoString_allRequiredFieldsSet_noExceptionattachmentUrls_initializedAsEmptyListCoverage Impact
Tests are pure POJO — no Spring context, no DB. Adds coverage for
User.getDisplayName()(all 3 branches) andTask.toString()(NPE paths).Trade-offs
assertThrows(NPE)) so that fixing the bug requires updating the tests — making the fix visible.Reproducibility
Test Status
✅ 17/17 tests pass (10 UserModelTest + 7 TaskModelTest)
✅ Existing test suite unaffected (pre-existing failures on
testGetQuarterandtestGetTaskStatisticsare unchanged)Add this agentic workflows to your repo
To install this agentic workflow, run