次のコードのjunitテストケースの書き方を教えてください。私が書いたものは、try本体に入りません。どうして..??
コード:-
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());
}
}