Skip to content

Commit ea3b36c

Browse files
committed
issue #10 : add rm command
1 parent 24f3332 commit ea3b36c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/main/java/io/github/benas/unixstream/UnixStream.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,4 +472,16 @@ static PrintWriter file(String filePath) throws IOException {
472472
*/
473473
void to(final PrintWriter printWriter) throws IOException;
474474

475+
/*
476+
* Miscellaneous methods
477+
*/
478+
479+
static void rm(final Path path) {
480+
try {
481+
Files.delete(path);
482+
} catch (IOException e) {
483+
throw new RuntimeException("Unable to delete file " + path.getFileName());
484+
}
485+
}
486+
475487
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.github.benas.unixstream.components;
2+
3+
import io.github.benas.unixstream.UnixStream;
4+
import org.junit.After;
5+
import org.junit.Test;
6+
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
14+
public class RmTest {
15+
16+
private Path foo = Paths.get("target/foo.txt");
17+
18+
@Test
19+
public void rm() throws IOException {
20+
Files.createFile(foo);
21+
assertThat(foo).exists();
22+
23+
UnixStream.rm(foo);
24+
25+
assertThat(foo).doesNotExist();
26+
}
27+
28+
@After
29+
public void tearDown() throws IOException {
30+
Files.deleteIfExists(foo);
31+
}
32+
}

0 commit comments

Comments
 (0)