title: EasyMock and File in Java
body: <p>I'm programming application and i need to Mock File to test it. My code below:</p>
  
  <pre><code>@Test
  public void testPostMail() throws Exception
  {
      Emailer instance = new Emailer();
      instance.setRecipientsFromFile(new File("list.txt"));
  }
  </code></pre>
  
  <p>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).</p>
  
  <p>I tried to import org.easymock.classextension.EasyMock and use it, but:</p>
  
  <p>1) I still get error "File is not an interface"</p>
  
  <p>2) classextension.EasyMock is deprecated, so I should use just EasyMock</p>
  
  <p>My not working EasyMock code:</p>
  
  <pre><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);
  
  // ...
  }
  </code></pre>
  
  <p>EDIT: I'm wondering to change from EasyMock to Mockito, because I heard more favourable opinions.</p>