Created
March 14, 2023 08:22
-
-
Save faizakram/1a61bf175d133f12dcef58470c2a42d2 to your computer and use it in GitHub Desktop.
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
package com.care.connection.careconnection; | |
import static org.junit.jupiter.api.Assertions.assertNotEquals; | |
import static org.mockito.Mockito.when; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.junit.jupiter.api.BeforeEach; | |
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 org.springframework.core.env.Environment; | |
import com.care.connection.careconnection.dto.DashboardDTO; | |
import com.care.connection.careconnection.repository.RequestRepository; | |
import com.care.connection.careconnection.repository.ResponseRepository; | |
import com.care.connection.careconnection.service.CareConnectionServiceImpl; | |
import com.care.connection.careconnection.utils.CommonConstant; | |
@ExtendWith(MockitoExtension.class) | |
public class ServiceClassTest extends CareConnectionApplicationTests{ | |
// @Autowired | |
// private WebApplicationContext webApplicationContext; | |
@InjectMocks | |
private CareConnectionServiceImpl careConnectionServiceImpl; | |
@Mock | |
private RequestRepository requestRepository; | |
@Mock | |
private ResponseRepository responseRepository; | |
@Mock | |
private Environment environment; | |
// private MockMvc mockMvc; | |
private DashboardDTO dashboardDTO; | |
private List<String> listString; | |
@BeforeEach | |
public void setup() { | |
//mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); | |
dashboardDTO = new DashboardDTO(); | |
listString = new ArrayList<>(); | |
listString.add(CommonConstant.SUCCESS_STATUS); | |
} | |
@Test | |
public void getDashboardTest() { | |
when(requestRepository.getDashboard(CommonConstant.SUCCESS_STATUS, CommonConstant.FAILURE)).thenReturn(dashboardDTO); | |
DashboardDTO dashboardDTO = careConnectionServiceImpl.getDashboard(); | |
assertNotEquals(dashboardDTO, null); | |
} | |
@Test | |
public void getStatus() { | |
when(requestRepository.getStatus()).thenReturn(listString); | |
List<String> listString1 = careConnectionServiceImpl.getStatus(); | |
assertNotEquals(listString1, null); | |
} | |
// @Test | |
// public void addDummyData() throws Exception { | |
// Mockito.when(careConnectionService.addDummyData()).thenReturn(true); | |
// mockMvc.perform(get("/request/dummy-data")).andExpect(status().isOk()); | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment