I am trying to write unit test for a method that calls FileWriter. I am using JUnit 4.8, Powermock and Mockito. The method I'm testing looks like this.
public void methodToTest(String fileName, String text){ File file = new File (someStaticString)
If the file and the Writer file are declared outside the method, I can make fun of them using mockito and powermock so that I can check for possible scripts that might happen if the method has been called since I have been doing BDD. However, I cannot modify the codes that I am testing as other developers have created them (although I believe that the developers are responsible for creating the unit test).
I am wondering how (if possible) to mock objects under such a way as a file and fw. How about if there are objects created in if () or loop ()? Can they taunt?
If what I think is impossible, what recommendation can you offer to test such methods? I also found out about JUnit TemporaryFolder. Can I use this instead of a file to create folders and a file?
Thanks.
source share