Added some tests for the IOUtil class
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
26ec5d2782
commit
204a5e15f1
@ -1,4 +1,9 @@
|
|||||||
pipeline:
|
pipeline:
|
||||||
|
test:
|
||||||
|
image: maven:3-jdk-11
|
||||||
|
commands:
|
||||||
|
- mvn test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3-jdk-11
|
image: maven:3-jdk-11
|
||||||
commands:
|
commands:
|
||||||
|
@ -14,9 +14,9 @@ public class IOUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String resolveTilda(String path) {
|
public static String resolveTilda(String path) {
|
||||||
if (path.startsWith("~" + File.separator)) {
|
if (path.startsWith("~" + File.separator) || path.equals("~")) {
|
||||||
path = System.getProperty("user.home") + path.substring(1);
|
path = System.getProperty("user.home") + path.substring(1);
|
||||||
} else if (path.startsWith("~")) {
|
} else if ((!path.equals("~")) && path.startsWith("~")) {
|
||||||
// here you can implement reading homedir of other users if you care
|
// here you can implement reading homedir of other users if you care
|
||||||
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
||||||
}
|
}
|
||||||
|
28
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
28
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package tech.bitgoblin.io;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class IOUtilsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateDirectory() {
|
||||||
|
IOUtils.createDirectory("test-temp.txt");
|
||||||
|
assertTrue(new File("test-temp.txt").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExpandTilda() {
|
||||||
|
String homeExpanded = IOUtils.resolveTilda("~");
|
||||||
|
assertTrue(!homeExpanded.equals("~"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=UnsupportedOperationException.class)
|
||||||
|
public void shouldFailExpandExplicitTilda() {
|
||||||
|
IOUtils.resolveTilda("~test");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user