-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Junit testcase for common-api * resolved sonarcloud errors #2 * commented code removed pr#3 * Junit test case-completed --------- Co-authored-by: IN40068837 <[email protected]>
- Loading branch information
Showing
265 changed files
with
46,415 additions
and
99 deletions.
There are no files selected for viewing
464 changes: 393 additions & 71 deletions
464
...st/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationControllerTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/test/java/com/iemr/common/controller/brd/BRDIntegrationControllerTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.iemr.common.controller.brd; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.iemr.common.service.brd.BRDIntegrationService; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BRDIntegrationControllerTest { | ||
|
||
@Mock | ||
private BRDIntegrationService integrationService; | ||
|
||
@InjectMocks | ||
private BRDIntegrationController controller; | ||
|
||
@Test | ||
void getDetailsSuccess() throws Exception { | ||
// Arrange | ||
String request = new JSONObject().put("startDate", "2021-01-01").put("endDate", "2021-01-31").toString(); | ||
String expectedResponse = "Expected BRD Data"; | ||
when(integrationService.getData(anyString(), anyString())).thenReturn(expectedResponse); | ||
|
||
// Act | ||
String actualResponse = controller.getDetails(request); | ||
|
||
// Assert | ||
assertNotNull(actualResponse); | ||
assertTrue(actualResponse.contains(expectedResponse)); | ||
|
||
// Verify that the integration service is called once with any strings | ||
verify(integrationService).getData(anyString(), anyString()); | ||
} | ||
|
||
@Test | ||
void getDetailsFailure() { | ||
// Arrange | ||
String request = "invalid JSON"; | ||
|
||
// Act | ||
String actualResponse = controller.getDetails(request); | ||
|
||
// Assert | ||
assertNotNull(actualResponse); | ||
assertTrue(actualResponse.contains("Unable to get BRD data")); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.