Skip to content

Commit

Permalink
Fix for issue 654 ... adding unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tglaeser committed Aug 1, 2020
1 parent 0019984 commit d537dd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public void paddedCellApplyCheck() throws Exception {
assertFile(converge.file).hasContent(""); // converge -> converges
assertFile(diverge.file).hasContent("CCC"); // diverge -> no change

assertFileAttributesEqual(wellbehaved.file, wellbehaved.outputFile);

// After apply, check should pass
wellbehaved.check();
cycle.check();
Expand Down
11 changes: 10 additions & 1 deletion testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2020 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclFileAttributeView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -166,6 +168,13 @@ protected void assertOnResources(FormatterFunc step, String unformattedPath, Str
Assert.assertEquals(expected, formatted);
}

/** Reads file attributes from the output file and compares it to the attributes from the input file. */
protected void assertFileAttributesEqual(File input, File output) throws IOException {
List<AclEntry> inputAttributes = Files.getFileAttributeView(input.toPath(), AclFileAttributeView.class).getAcl();
List<AclEntry> outputAttributes = Files.getFileAttributeView(output.toPath(), AclFileAttributeView.class).getAcl();
Assertions.assertThat(outputAttributes).isEqualTo(inputAttributes);
}

@CheckReturnValue
protected ReadAsserter assertFile(String path) throws IOException {
return new ReadAsserter(newFile(path));
Expand Down

0 comments on commit d537dd4

Please sign in to comment.