| New file |
| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.Mockito.doAnswer; |
| | | import static org.mockito.Mockito.mock; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.Map; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.system.domain.TBatteryGroupTemplate; |
| | | import com.ruoyi.system.service.ITBatteryGroupTemplateService; |
| | | |
| | | /** 电池组模板新增接口合同测试。 */ |
| | | class TBatteryGroupTemplateControllerTest |
| | | { |
| | | @Test |
| | | void addShouldReturnGeneratedTemplateId() |
| | | { |
| | | ITBatteryGroupTemplateService service = mock(ITBatteryGroupTemplateService.class); |
| | | doAnswer(invocation -> { |
| | | invocation.<TBatteryGroupTemplate>getArgument(0).setTemplateId(21L); |
| | | return 1; |
| | | }).when(service).insertBatteryGroupTemplate(any(TBatteryGroupTemplate.class)); |
| | | |
| | | TBatteryGroupTemplateController controller = new TBatteryGroupTemplateController() |
| | | { |
| | | @Override |
| | | public String getUsername() |
| | | { |
| | | return "admin"; |
| | | } |
| | | }; |
| | | ReflectionTestUtils.setField(controller, "batteryGroupTemplateService", service); |
| | | TBatteryGroupTemplate template = new TBatteryGroupTemplate(); |
| | | template.setTemplateName("模板"); |
| | | template.setFieldIds(Collections.singletonList(3L)); |
| | | |
| | | AjaxResult result = controller.add(template); |
| | | |
| | | assertEquals(21L, ((Map<?, ?>) result.get("data")).get("templateId")); |
| | | } |
| | | } |