【发布时间】:2020-05-21 18:10:14
【问题描述】:
如何在不创建新目录的情况下检查if?
String st = "exemple";
String path = "exemple";
if (!new File(path).exists() && !new File(path).mkdirs()) {
throw new ComumException("trocaarquivos.erro.exemple", path);
}
我的尝试:
@PrepareForTest(File.class )
File myFile = PowerMockito.mock(File.class);
PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(myFile);
PowerMockito.when(!new File(anyString()).exists() && !new File(anyString()).mkdirs()).thenReturn(true);
和
Mockito.when(myFile.exists()).thenReturn(true);
Mockito.when(myFile.mkdirs()).thenReturn(true);
3 天试图覆盖此代码。
【问题讨论】:
-
我建议您将您的姓名和术语翻译成英文,这样更容易获得帮助。 @guimas
标签: java mockito powermock powermockito easymock