🧪 test: Improve AddHoldingUseCase validations and test coverage#42
Conversation
Added validations for blank name, negative, and NaN `avgCost` in `AddHoldingUseCase` to ensure robust data integrity. Added comprehensive tests in `AddHoldingUseCaseTest` for the new error conditions to verify the expected `IllegalArgumentException` is thrown correctly. Co-authored-by: Max97k <14903047+Max97k@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request introduces validation checks for the holding's name and average cost in AddHoldingUseCase, along with corresponding unit tests in AddHoldingUseCaseTest. The feedback suggests refining the exception message for an invalid average cost to better describe the NaN case, updating the associated test assertions, and removing redundant runBlocking scopes from the test cases to clean up the test code.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (holding.avgCost.isNaN() || holding.avgCost < 0) { | ||
| throw IllegalArgumentException("Average cost cannot be negative") | ||
| } |
There was a problem hiding this comment.
The exception message 'Average cost cannot be negative' is misleading when holding.avgCost is NaN. Consider updating the message to accurately reflect both conditions, such as 'Average cost must be a valid non-negative number'.
| if (holding.avgCost.isNaN() || holding.avgCost < 0) { | |
| throw IllegalArgumentException("Average cost cannot be negative") | |
| } | |
| if (holding.avgCost.isNaN() || holding.avgCost < 0) { | |
| throw IllegalArgumentException("Average cost must be a valid non-negative number") | |
| } |
| } | ||
|
|
||
| @Test | ||
| fun `invoke with blank name throws exception`() = runBlocking { |
There was a problem hiding this comment.
Since the only suspending call is inside the runBlocking block passed to assertThrows, wrapping the entire test function in runBlocking is redundant. You can remove = runBlocking from the test function signature.
| fun `invoke with blank name throws exception`() = runBlocking { | |
| fun `invoke with blank name throws exception`() { |
| } | ||
|
|
||
| @Test | ||
| fun `invoke with negative avgCost throws exception`() = runBlocking { |
There was a problem hiding this comment.
Since the only suspending call is inside the runBlocking block passed to assertThrows, wrapping the entire test function in runBlocking is redundant. You can remove = runBlocking from the test function signature.
| fun `invoke with negative avgCost throws exception`() = runBlocking { | |
| fun `invoke with negative avgCost throws exception`() { |
| runBlocking { useCase(holding) } | ||
| } | ||
|
|
||
| assertEquals("Average cost cannot be negative", exception.message) |
There was a problem hiding this comment.
| } | ||
|
|
||
| @Test | ||
| fun `invoke with NaN avgCost throws exception`() = runBlocking { |
There was a problem hiding this comment.
Since the only suspending call is inside the runBlocking block passed to assertThrows, wrapping the entire test function in runBlocking is redundant. You can remove = runBlocking from the test function signature.
| fun `invoke with NaN avgCost throws exception`() = runBlocking { | |
| fun `invoke with NaN avgCost throws exception`() { |
| runBlocking { useCase(holding) } | ||
| } | ||
|
|
||
| assertEquals("Average cost cannot be negative", exception.message) |
There was a problem hiding this comment.
| ) | ||
|
|
||
| useCase(holding) | ||
| runBlocking { useCase(holding) } |
🎯 What: The testing gap in
AddHoldingUseCasewas addressed by adding required data integrity validations for blank name and invalidavgCostvalues.📊 Coverage: The following scenarios are now tested and verified:
✨ Result: Enhanced the reliability and stability of adding new holdings with expanded test coverage catching real potential bugs before saving.
PR created automatically by Jules for task 4556632060158720628 started by @Max97k