Created
April 2, 2012 18:46
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
public class FileCreatorTestWithCustomValidator { | |
private FileCreator fileCreator = new FileCreator(); | |
private String fileName = "file.txt"; | |
@Before | |
public void setUp() throws IOException { | |
Files.deleteIfExists(Paths.get(fileName)); | |
} | |
@Test | |
public void shouldCreateFile() throws InterruptedException { | |
// when | |
fileCreator.createFile(fileName); | |
// then | |
boolean fileExists = checkThatFileExists(fileName); | |
assertThat(fileExists, is(true)); | |
} | |
private boolean checkThatFileExists(String fileName) | |
throws InterruptedException { | |
for (int i = 0; i < 100; i++) { | |
Path path = Paths.get(fileName); | |
try { | |
assertThat(path, exists()); | |
return true; | |
} catch (AssertionError e) { | |
// ignore exception | |
} | |
Thread.sleep(100); | |
} | |
throw new AssertionError("Timeout exceeded"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment