I'm programming application and i need to Mock File to test it. My code below:
@Test
public void testPostMail() throws Exception
{
Emailer instance = new Emailer();
instance.setRecipientsFromFile(new File("list.txt"));
}
The problem is, I don't want to be dependent on file on my hdd (of course I can make a file with a proper content and after a test delete it, but I want to do it with EasyMock).
I tried to import org.easymock.classextension.EasyMock and use it, but:
1) I still get error "File is not an interface"
2) classextension.EasyMock is deprecated, so I should use just EasyMock
My not working EasyMock code:
@Test
public void testSetReceipientsFromFile() throws Exception
{
File file = EasyMock.createMock(File.class);
FileReader in = EasyMock.createMock(FileReader.class);
BufferedReader br = EasyMock.createMock(BufferedReader.class);
EasyMock.expect(new FileReader(file)).andReturn(in);
EasyMock.expect(new BufferedReader(in)).andReturn(br);
EasyMock.expect(br.readLine()).andReturn("test@mail.com");
EasyMock.expect(br.readLine()).andReturn("test2@mail2.com");
EasyMock.replay(file, in, br);
EasyMock.verify(file, in, br);
// ...
}
EDIT: I'm wondering to change from EasyMock to Mockito, because I heard more favourable opinions.