Files
dragoon/src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Gregory Ballantine 8c36855593
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Removed some unused imports; closed an open file in a unit test
2022-06-16 00:12:16 -04:00

64 lines
1.6 KiB
Java

package tech.bitgoblin.io;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
public class IOUtilsTest {
private static String testDir = "test-temp";
private static String testFile = "test.txt";
@Test
public void shouldCreateDirectory() {
IOUtils.createDirectory(testDir);
assertTrue(new File(testDir).exists());
}
@Test
public void shouldExpandTilda() {
String homeExpanded = IOUtils.resolveTilda("~");
assertTrue(!homeExpanded.equals("~"));
}
@Test(expected=UnsupportedOperationException.class)
public void shouldFailExpandExplicitTilda() {
IOUtils.resolveTilda("~test");
}
@Test
public void fileShouldBeLocked() throws IOException {
RandomAccessFile raf = new RandomAccessFile(testFile, "rw");
assertTrue(IOUtils.isFileLocked(new File(testFile)));
raf.close();
}
@Test
public void fileShouldNotBeLocked() throws IOException {
RandomAccessFile raf = new RandomAccessFile("test.txt", "rw");
raf.close();
assertFalse(IOUtils.isFileLocked(new File(testFile)));
}
@BeforeClass
// ensure that test files are created before running tests
public static void setup() throws IOException {
new File(testFile).createNewFile();
}
@AfterClass
// ensure test files are cleaned up from the environment
public static void cleanup() {
new File(testDir).delete();
new File(testFile).delete();
}
}