Last active
February 21, 2019 17:09
-
-
Save wkorando/ae40ec895248dff6ddcecf2ab86ad364 to your computer and use it in GitHub Desktop.
This file contains 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
@TestMethodOrder(OrderAnnotation.class) | |
public class TestTempDir { | |
@TempDir | |
static Path classTempDir; | |
@TempDir | |
static File classTempDirAsFile; | |
@Test | |
@Order(1) | |
public void useAsClassValue() throws IOException { | |
File file = classTempDir.resolve("temp.txt").toFile(); | |
FileUtils.write(file, "A", StandardCharsets.ISO_8859_1, true); | |
assertEquals("A", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
@Test | |
@Order(2) | |
public void useAsClassValuePart2() throws IOException { | |
File file = classTempDir.resolve("temp.txt").toFile(); | |
FileUtils.write(file, "B", StandardCharsets.ISO_8859_1, true); | |
assertEquals("AB", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
@Test | |
@Order(3) | |
public void injectAsMethodValue(@TempDir Path argumentTempDir) throws IOException { | |
File file = argumentTempDir.resolve("temp.txt").toFile(); | |
FileUtils.write(file, "C", StandardCharsets.ISO_8859_1, true); | |
assertEquals("ABC", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
@Test | |
@Order(4) | |
public void injectAsMethodValuePart2(@TempDir Path argumentTempDir) throws IOException { | |
File file = argumentTempDir.resolve("temp.txt").toFile(); | |
FileUtils.write(file, "D", StandardCharsets.ISO_8859_1, true); | |
assertEquals("ABCD", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
@Test | |
@Order(5) | |
public void useAsClassFileValue() throws IOException { | |
File file = new File(classTempDirAsFile, "temp.txt"); | |
FileUtils.write(file, "E", StandardCharsets.ISO_8859_1, true); | |
assertEquals("ABCDE", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
@Test | |
@Order(6) | |
public void injectAsMethodFileValue(@TempDir File tempFile) throws IOException { | |
File file = new File(classTempDirAsFile, "temp.txt"); | |
FileUtils.write(file, "F", StandardCharsets.ISO_8859_1, true); | |
assertEquals("ABCDEF", FileUtils.readFileToString(file, StandardCharsets.ISO_8859_1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment