Created
October 23, 2010 17:27
-
-
Save searls/642467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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