Skip to content

Commit

Permalink
Junit/testcases by Indrani (#99)
Browse files Browse the repository at this point in the history
* 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
Vidyaaa24 and IN40068837 authored Apr 15, 2024
1 parent 18d4e1c commit ff8a72b
Show file tree
Hide file tree
Showing 265 changed files with 46,415 additions and 99 deletions.

Large diffs are not rendered by default.

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"));

}

}
Loading

0 comments on commit ff8a72b

Please sign in to comment.