package pwc.taxtech.atms.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.springframework.web.multipart.commons.CommonsMultipartFile; import pwc.taxtech.atms.common.CommonUtils; import pwc.taxtech.atms.dto.OperationResultDto; import pwc.taxtech.atms.dto.customer.CustomerDto; import pwc.taxtech.atms.dto.customer.CustomerValidateInfoDto; import pwc.taxtech.atms.service.CustomerService; @RunWith(MockitoJUnitRunner.class) public class CustomerControllerTest { @Mock private CustomerService customerService; @Mock private CommonsMultipartFile commonsMultipartFile; @InjectMocks private CustomerController customerController; @Test public void addRangeNotNullResult() { List<CustomerDto> customerDtoList = new ArrayList<>(); CustomerDto customerDto = new CustomerDto(); customerDto.setID(CommonUtils.getUUID()); customerDto.setName("customer-name"); customerDto.setCode("customer-code"); customerDto.setEnterPriseAccountID(CommonUtils.getUUID()); customerDtoList.add(customerDto); List<OperationResultDto<CustomerDto>> operationResultDtoList = new ArrayList<>(); when(customerService.addRange(customerDtoList)).thenReturn(operationResultDtoList); assertThat(customerController.addRange(customerDtoList)).isNotNull(); } @Test public void getByIDNotNullResult() { String setId = CommonUtils.getUUID(); when(customerService.getByEnterpriseAccountSetID(setId)).thenReturn(new CustomerValidateInfoDto()); assertThat(customerController.getByID(setId)).isNotNull(); } @Test public void getNotNullResult() { List<CustomerDto> customerDtoList = new ArrayList<>(); when(customerService.getCustomer()).thenReturn(customerDtoList); assertThat(customerController.getCustomer()).isNotNull(); } @Test public void deleteRangeNotNullResult() { List<CustomerDto> customerDtoList = new ArrayList<>(); CustomerDto customerDto = new CustomerDto(); customerDto.setID(CommonUtils.getUUID()); customerDto.setName("customer-name"); customerDto.setCode("customer-code"); customerDto.setEnterPriseAccountID(CommonUtils.getUUID()); customerDtoList.add(customerDto); OperationResultDto<String> operationResultDto = new OperationResultDto<>(); when(customerService.deleteRange(customerDtoList)).thenReturn(operationResultDto); assertThat(customerController.deleteRange(customerDtoList)).isNotNull(); } @Test public void updateRangeNotNullResult() { List<CustomerDto> customerDtoList = new ArrayList<>(); CustomerDto customerDto = new CustomerDto(); customerDto.setID(CommonUtils.getUUID()); customerDto.setName("customer-name"); customerDto.setCode("customer-code"); customerDto.setEnterPriseAccountID(CommonUtils.getUUID()); customerDtoList.add(customerDto); List<OperationResultDto<CustomerDto>> operationResultDtoList = new ArrayList<>(); when(customerService.updateRange(customerDtoList)).thenReturn(operationResultDtoList); assertThat(customerController.updateRange(customerDtoList)).isNotNull(); } @SuppressWarnings("rawtypes") @Test public void uploadNullFile() { CommonsMultipartFile inputFile = null; String enterpriseAccountID = "enterpriseAccountID1"; String action = "1"; Object obj = customerController.upload(inputFile, enterpriseAccountID, action); OperationResultDto result = (OperationResultDto) obj; Assert.assertEquals(Boolean.FALSE, result.getResult()); } @Test public void uploadFile() { String enterpriseAccountID = "enterpriseAccountID1"; String action = "1"; when(commonsMultipartFile.getSize()).thenReturn(1L); Object obj = customerController.upload(commonsMultipartFile, enterpriseAccountID, action); Assert.assertNull(obj); } }