@Test public void testInit_null() throws Exception{ // when(ftpClientService.getFtpClient(any())).thenReturn(null); //when(task.getCleanDirs().add(any())).thenReturn(null); FileCleanTask task=new FileCleanTask(); task.getCleanDirs().add(""); List<FileCleanTask>tasks=Arrays.asList(task); if(tasks.isEmpty()) { try { Thread.sleep(60000); } catch (InterruptedException e) { log.error("InterruptedException while sleeping",e); } } // when(ftpManagerClient.getCleanTasks(0)).thenReturn(null); //doNothing().when(task.).add(any()); cleanTaskPollService.init(); }怎么调成tasks.isEmpty为1使得UT
时间: 2024-03-27 20:40:01 浏览: 75
可以通过以下方式将 `tasks.isEmpty()` 的返回值设置为 1:
```
@Test
public void testInit_null() throws Exception{
// when(ftpClientService.getFtpClient(any())).thenReturn(null);
//when(task.getCleanDirs().add(any())).thenReturn(null);
FileCleanTask task=new FileCleanTask();
task.getCleanDirs().add("");
List<FileCleanTask>tasks=Arrays.asList(task);
if(tasks.size() == 0) // 修改此处的判断条件
{
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
log.error("InterruptedException while sleeping",e);
}
}
// when(ftpManagerClient.getCleanTasks(0)).thenReturn(null);
//doNothing().when(task.).add(any());
cleanTaskPollService.init();
}
```
将原来的 `tasks.isEmpty()` 改为 `tasks.size() == 0` 即可。
阅读全文