有人可以告诉我如何为以下代码编写一个 junit 测试用例。我写的那个没有进入尝试正文。为什么..??
代码:-
public void dataImport ( String scheme , String dataSource , String savePath ) throws ImportException {
LOG.debug("Entered");
final InputStream inputStream = null ;
try {
String host = "localhost";
String user = "user";
String pass = "pass";
String filePath ="/A/a1.txt"; ( this are actually extracted from dataSource )
FTPClient ftpClient = new FTPClient();
ftpClient.connect(host, 21);
ftpClient.login(user, pass);
inputStream = ftpClient.retrieveFileStream(filePath);
//saving it to the file System
}
catch (final IOException ex) {
throw new ImportException(ex.getMessage(), ex);
}
finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (final IOException e) {
throw new ImportException(e.getMessage(), e);
}
}
}
Junit测试用例:-
@Test(expected=NullPointerException.class)
public void testImportData () throws ImportException , IOException {
FTPImporter fi = new FTPImporter();
try{
fi.dataImport("ftp" , "ftp://user:pass@localhost/A/a1.txt" , "desti" );
fail("ere");
}
catch(ImportException e ){
assertNotNull(e.getMessage());
}
}