I have a class, for example:
class ClassA { private static File myDir;
So basically, I want to test this class by mocking the File class so that when I call list () it will return a list of strings that I define in my test class.
I have the following, but it doesnβt work at the moment, maybe something obvious that I am doing wrong - I am new to JMockit - any help is greatly appreciated!
@Mocked("list") File myDir; @Test public void testClassA() { final String[] files = {"file1-bla.txt"}; new NonStrictExpectations() {{ new File(anyString).list(); returns(files); }}; String returnedFileName = Deencapsulation.invoke(ClassA.class, "findFile","file1.txt");
When performing the above test, I get a NullPointerException for the myDir field in ClassA - so it looks like it is being mocked incorrectly?
source share