我已经使用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
试试这个
expect(ftpClient.removeDirectory(dirName)).andReturn(true);