| | |
| | | import static org.mockito.Mockito.when; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.jupiter.api.extension.ExtendWith; |
| | |
| | | import org.mockito.junit.jupiter.MockitoExtension; |
| | | import com.ruoyi.system.domain.TBatteryGroup; |
| | | import com.ruoyi.system.domain.TBatteryGroupBattery; |
| | | import com.ruoyi.system.domain.TBatteryGroupRelationField; |
| | | import com.ruoyi.system.mapper.TBatteryGroupMapper; |
| | | |
| | | /** 电池组 Service 单元测试。 */ |
| | |
| | | .map(TBatteryGroupBattery::getBatteryNo).toList()); |
| | | verify(batteryGroupMapper, never()).batchInsertRelationFields(anyList()); |
| | | } |
| | | |
| | | @Test |
| | | void updateShouldPersistStatusAndTemplateFieldValue() |
| | | { |
| | | TBatteryGroup current = new TBatteryGroup(); |
| | | current.setGroupId(12L); |
| | | current.setStatus("0"); |
| | | TBatteryGroup group = new TBatteryGroup(); |
| | | group.setGroupId(12L); |
| | | group.setGroupName("样品组"); |
| | | group.setModel("M-01"); |
| | | group.setStatus("1"); |
| | | group.setBatteryNos(Collections.singletonList("BAT-01")); |
| | | group.setTemplateId(5L); |
| | | TBatteryGroupRelationField relation = new TBatteryGroupRelationField(); |
| | | relation.setBatteryGroupFieldId(7L); |
| | | relation.setFieldValue("72Ah"); |
| | | group.setTemplateFieldRelations(Collections.singletonList(relation)); |
| | | |
| | | when(batteryGroupMapper.selectBatteryGroupById(12L)).thenReturn(current); |
| | | when(batteryGroupMapper.countTestingByGroupId(12L)).thenReturn(0); |
| | | when(batteryGroupMapper.selectBatteryByNo("BAT-01", 12L)).thenReturn(null); |
| | | when(batteryGroupMapper.selectTemplate(5L)).thenReturn(new TBatteryGroup()); |
| | | when(batteryGroupMapper.selectTemplateFieldIds(5L)).thenReturn(Collections.singletonList(7L)); |
| | | when(batteryGroupMapper.selectValidTemplateFields(5L, Collections.singletonList(7L))) |
| | | .thenReturn(Collections.singletonList(relation)); |
| | | when(batteryGroupMapper.updateBatteryGroup(group)).thenReturn(1); |
| | | |
| | | assertEquals(1, batteryGroupService.updateBatteryGroup(group)); |
| | | |
| | | verify(batteryGroupMapper).updateBatteryGroup(group); |
| | | ArgumentCaptor<List<TBatteryGroupRelationField>> captor = ArgumentCaptor.forClass(List.class); |
| | | verify(batteryGroupMapper).batchInsertRelationFields(captor.capture()); |
| | | assertEquals("72Ah", captor.getValue().get(0).getFieldValue()); |
| | | assertEquals("1", group.getStatus()); |
| | | } |
| | | } |