aI'm trying to test code which is inside a try-catch statement such as:
@Service
public class DoSomething {
public void uploadFile(String filename) {
try{
File file = new File(filename + ".txt");
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
// ...other code
method2(filename)
// ... more code
} catch(...) {...}
}
public void method2(filename){...do something here}
}
I want to test what's inside of the try statement however I'm unable to mock the InputStream so it just goes straight to the catch statement when I try to Spy on uploadFile. How can I mock the InputStream so it returns a file I have in the temp folder or just not go to the catch statement such that I may test the rest of my code. i.e.) I'm trying to verify method2 will be within the uploadFile method.
Aucun commentaire:
Enregistrer un commentaire