Skip to content

Commit c4c5822

Browse files
committed
feat: allow further actions with file
1 parent 3021140 commit c4c5822

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,41 @@ private WriteAsserter(File file) {
235235
this.file = file;
236236
}
237237

238-
public File toLines(String... lines) {
238+
public WriteAsserter toLines(String... lines) {
239239
return toContent(String.join("\n", Arrays.asList(lines)));
240240
}
241241

242-
public File toContent(String content) {
242+
public WriteAsserter toContent(String content) {
243243
return toContent(content, StandardCharsets.UTF_8);
244244
}
245245

246-
public File toContent(String content, Charset charset) {
246+
public WriteAsserter toContent(String content, Charset charset) {
247247
ThrowingEx.run(() -> {
248248
Files.write(file.toPath(), content.getBytes(charset));
249249
});
250-
return file;
250+
return this;
251251
}
252252

253-
public File toResource(String path) {
253+
public WriteAsserter toResource(String path) {
254254
ThrowingEx.run(() -> {
255255
Files.write(file.toPath(), getTestResource(path).getBytes(StandardCharsets.UTF_8));
256256
});
257-
return file;
257+
return this;
258258
}
259259

260-
public File deleted() throws IOException {
260+
public WriteAsserter deleted() throws IOException {
261261
Files.delete(file.toPath());
262+
return this;
263+
}
264+
265+
public WriteAsserter makeExecutable() {
266+
if (!file.setExecutable(true)) {
267+
throw ThrowingEx.asRuntime(new IOException("Failed to set executable flag on " + file));
268+
}
269+
return this;
270+
}
271+
272+
public File getFile() {
262273
return file;
263274
}
264275
}

0 commit comments

Comments
 (0)