-
Notifications
You must be signed in to change notification settings - Fork 4.3k
(test) TRUNK-6603: Add unit tests for ProviderService APIException #5997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
c6263da
dd55804
a16b313
9fd724f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.openmrs.Provider; | ||
| import org.openmrs.api.APIException; | ||
| import org.openmrs.api.db.ProviderDAO; | ||
| import org.openmrs.api.impl.ProviderServiceImpl; | ||
|
|
||
| public class ProviderServiceImplTest { | ||
|
Check warning on line 13 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java
|
||
| private ProviderServiceImpl service; | ||
| private ProviderDAO dao; | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
|
Check warning on line 18 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java
|
||
| service = new ProviderServiceImpl(); | ||
| dao = mock(ProviderDAO.class); | ||
| service.setProviderDAO(dao); | ||
| } | ||
|
|
||
| @Test | ||
| public void getProviderByUuid_shouldReturnProvider_whenProviderExists() { | ||
|
Check warning on line 25 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java
|
||
| String uuid = "test-uuid"; | ||
| Provider provider = new Provider(); | ||
| when(dao.getProviderByUuid(uuid)).thenReturn(provider); | ||
| Provider result = service.getProviderByUuid(uuid); | ||
| assertNotNull(result); | ||
| assertEquals(provider, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void getProviderByUuid_shouldThrowException_whenProviderNotFound() { | ||
|
Check warning on line 35 in api/src/test/java/org/openmrs/api/impl/ProviderServiceImplTest.java
|
||
| String uuid = "invalid-uuid"; | ||
| when(dao.getProviderByUuid(uuid)).thenReturn(null); | ||
| assertThrows(APIException.class, () -> { | ||
| service.getProviderByUuid(uuid); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra spaces