Skip to content

(test) TRUNK-6603: Add unit tests for ProviderService APIException#5997

Open
AshThe25 wants to merge 4 commits intoopenmrs:masterfrom
AshThe25:test-provider-null-handling
Open

(test) TRUNK-6603: Add unit tests for ProviderService APIException#5997
AshThe25 wants to merge 4 commits intoopenmrs:masterfrom
AshThe25:test-provider-null-handling

Conversation

@AshThe25
Copy link
Copy Markdown

Description

This code adds unit tests for getProviderByUuid. The tests ensure that the method behaves correctly if a provider is found or not.

Tests

  • Returns provider if found
  • Throws APIException if provider is null

Context

This code is an extension of the previous fix that prevents silent returns of null.

if (provider == null) {
throw new APIException("Provider not found for uuid: " + uuid);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove extra spaces before and after this if() statement

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've removed wildcard imports and replaced them with explicit imports.

Also fixed formatting issues and removed extra spaces for consistency.

Updated the PR title for better clarity.

@@ -0,0 +1,46 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Copy link
Copy Markdown
Contributor

@tendomart tendomart Mar 30, 2026

Choose a reason for hiding this comment

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

Remove wild cards, it's a must to do actual imports not generic wild card imports

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! I've removed wildcard imports and replaced them with explicit imports.

Also fixed formatting issues and removed extra spaces for consistency.


when(dao.getProviderByUuid(uuid)).thenReturn(provider);

Provider result = service.getProviderByUuid(uuid);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove extra spaces

@Test
public void getProviderByUuid_shouldThrowException_whenProviderNotFound() {
String uuid = "invalid-uuid";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here

@tendomart
Copy link
Copy Markdown
Contributor

Improve your title by adding The name of the Ticket you're working on, if any, add link to Ticket if any.

@AshThe25 AshThe25 force-pushed the test-provider-null-handling branch from cae7a18 to c6263da Compare March 30, 2026 13:46
@AshThe25
Copy link
Copy Markdown
Author

Improve your title by adding The name of the Ticket you're working on, if any, add link to Ticket if any.

Thanks for the feedback! I've removed wildcard imports and replaced them with explicit imports.

Also fixed formatting issues and removed extra spaces for consistency.

Updated the PR title for better clarity.

@AshThe25 AshThe25 changed the title test(provider): add unit tests for getProviderByUuid (test) TRUNK-6603: Add unit tests for ProviderService APIException Mar 30, 2026
@AshThe25 AshThe25 requested a review from tendomart March 30, 2026 16:47
@Kanishka680
Copy link
Copy Markdown

Excellent addition of unit tests for edge cases. It's important to verify how the APIException handles null messages.

@AshThe25
Copy link
Copy Markdown
Author

Excellent addition of unit tests for edge cases. It's important to verify how the APIException handles null messages.

THANKS A LOT KANISHKA MEANS A LOT

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@Kanishka680 Kanishka680 left a comment

Choose a reason for hiding this comment

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

Excellent addition of unit tests for edge cases. It's important to verify how the APIException handles null messages.

Copy link
Copy Markdown

@Kanishka680 Kanishka680 left a comment

Choose a reason for hiding this comment

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

The implementation of the pluggable validator looks very modular. Great use of the UserService interface.

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.

3 participants