public Boolean deletePlaningLine(Long lineId) { TransactionTemplateWrapper.MessageHolder messageHolder = new TransactionTemplateWrapper.MessageHolder(); return new TransactionTemplateWrapper<Boolean>(transactionTemplate, eventPublisherDelegate) .doInTransaction(messageHolder, new TransactionTemplateWrapper.TransactionCallbackWrapper<>(() -> { ExpPlaningLinePointDataParam expPlaningLinePointDataParam = new ExpPlaningLinePointDataParam(); ExpPlaningLinePointDataParam.Criteria criteria = expPlaningLinePointDataParam.createCriteria(); criteria.andLineIdEqualTo(lineId); expPlaningLinePointDataMapper.deleteByParam(expPlaningLinePointDataParam); expPlaningLineDataMapper.deleteByPrimaryKey(lineId); return true; 使用mockito单元测试
时间: 2024-01-10 20:03:06 浏览: 39
您可以使用 Mockito 进行单元测试,以下是可能的测试代码示例:
```
@RunWith(MockitoJUnitRunner.class)
public class PlanningLineServiceTest {
@Mock
private ExpPlaningLineDataMapper expPlaningLineDataMapper;
@Mock
private ExpPlaningLinePointDataMapper expPlaningLinePointDataMapper;
@InjectMocks
private PlanningLineService planningLineService;
@Test
public void testDeletePlaningLine() {
// Arrange
Long lineId = 1L;
// Act
boolean result = planningLineService.deletePlaningLine(lineId);
// Assert
assertTrue(result);
verify(expPlaningLinePointDataMapper).deleteByParam(any());
verify(expPlaningLineDataMapper).deleteByPrimaryKey(lineId);
}
}
```
在这个测试中,使用了 MockitoJUnitRunner 来运行测试,并且使用了 @Mock 和 @InjectMocks 注解来模拟依赖和注入依赖。在测试方法中,调用了待测试的方法,并验证是否成功删除了规划线及其相关点数据。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)