我使用Mockito和Powermockito编写了测试用例,但现在我必须使用EasyMock代替Mockito编写它们。我试过这样做但没有成功。 使用Mockito的测试案例:
public class FTPUtilsTest {
FTPUtils ftpUtils ;
FTPClient ftpClient =Mockito.mock(FTPClient.class);
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
PowerMockito.whenNew(FTPClient.class).withNoArguments().thenReturn(ftpClient);
ftpUtils = new FTPUtils("ace.dev.demo","user1","user1",21);
Mockito.when(ftpClient.isConnected()).thenReturn(true);
}
@Test
public void testRemoveDirectory() throws FileAgentException, IOException{
String dirName="removeDir";
Mockito.when(ftpClient.removeDirectory(dirName)).thenReturn(true);
assertTrue(ftpUtils.removeDirectory(dirName));
}
}
如何替换Mockito.when(ftpClient.removeDirectory(dirName)).thenReturn(true);
使用EasyMock
答案 0 :(得分:0)
试试这个
expect(ftpClient.removeDirectory(dirName)).andReturn(true);