Skip to content

🧪 test: Improve AddHoldingUseCase validations and test coverage#42

Merged
Max97k merged 1 commit into
mainfrom
improve/add-holding-usecase-tests-4556632060158720628
Jun 23, 2026
Merged

🧪 test: Improve AddHoldingUseCase validations and test coverage#42
Max97k merged 1 commit into
mainfrom
improve/add-holding-usecase-tests-4556632060158720628

Conversation

@Max97k

@Max97k Max97k commented Jun 22, 2026

Copy link
Copy Markdown
Owner

🎯 What: The testing gap in AddHoldingUseCase was addressed by adding required data integrity validations for blank name and invalid avgCost values.

📊 Coverage: The following scenarios are now tested and verified:

  • Blank symbol.
  • Blank name.
  • Negative, NaN, or zero quantities.
  • Negative or NaN average costs.

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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +17 to +19
if (holding.avgCost.isNaN() || holding.avgCost < 0) {
throw IllegalArgumentException("Average cost cannot be negative")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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'.

Suggested change
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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
fun `invoke with blank name throws exception`() = runBlocking {
fun `invoke with blank name throws exception`() {

}

@Test
fun `invoke with negative avgCost throws exception`() = runBlocking {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the assertion message to match the updated exception message for invalid average cost.

Suggested change
assertEquals("Average cost cannot be negative", exception.message)
assertEquals("Average cost must be a valid non-negative number", exception.message)

}

@Test
fun `invoke with NaN avgCost throws exception`() = runBlocking {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the assertion message to match the updated exception message for invalid average cost.

Suggested change
assertEquals("Average cost cannot be negative", exception.message)
assertEquals("Average cost must be a valid non-negative number", exception.message)

)

useCase(holding)
runBlocking { useCase(holding) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test function is already wrapped in runBlocking. Calling runBlocking again inside it is redundant and unnecessary. You can call useCase(holding) directly.

Suggested change
runBlocking { useCase(holding) }
useCase(holding)

@Max97k Max97k merged commit c8a8d32 into main Jun 23, 2026
1 check passed
@Max97k Max97k deleted the improve/add-holding-usecase-tests-4556632060158720628 branch June 23, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant