Skip to content

Instantly share code, notes, and snippets.

@searls
Created October 23, 2010 17:27
Show Gist options
  • Save searls/642467 to your computer and use it in GitHub Desktop.
Save searls/642467 to your computer and use it in GitHub Desktop.
package searls.dougu.examples;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.powermock.api.mockito.PowerMockito.*;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(FileUtils.class)
public class FileUtilsWrapperTest {
private FileUtilsWrapper sut = new FileUtilsWrapper();
private File file = mock(File.class);
@Before
public void powerfullyMockStaticClasses() {
mockStatic(FileUtils.class);
}
@Test
public void delegatesReadingFilesToFileUtils() throws IOException {
String expected = "contents";
when(FileUtils.readFileToString(file)).thenReturn(expected);
String result = sut.readFileToString(file);
assertThat(result,is(expected));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment