Skip to content

Commit

Permalink
disable test tied to os specific behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Coles committed Oct 7, 2022
1 parent 11776f7 commit a92baf3
Showing 1 changed file with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -71,19 +73,26 @@ public void findsFileInPackageBeforeOneAtRoot() throws Exception {

@Test
public void findsFileInCorrectPackageBeforeWronglyPackagedOnes() throws Exception {
createFile(root.resolve("com/example/correct/Foo.java"), "this one");
createFile(root.resolve("Foo.java"), "not this one");
createFile(root.resolve("com/example/Foo.java"), "not this one");
createFile(root.resolve("com/example/correct/Foo.java"), "correct");
createFile(root.resolve("Foo.java"), "in package default");
createFile(root.resolve("com/example/Foo.java"), "example");
createFile(root.resolve("com/example/wrong/Foo.java"), "not this one");
createFile(root.resolve("com/example/correct/wrong/Foo.java"), "not this one");
Optional<Reader> actual = testee.locate(singletonList("com.example.correct.Foo"), "Foo.java");
assertThat(content(actual)).isEqualTo("this one");

assertThat(findFor("com.example.correct.Foo", "Foo.java")).isEqualTo("correct");
assertThat(findFor("Foo", "Foo.java")).isEqualTo("in package default");
assertThat(findFor("com.example.Foo", "Foo.java")).isEqualTo("example");
}

@Test
public void findsFileInRootBeforeOneInWrongPackage() throws Exception {
createFile(root.resolve("com/example/other/Foo.java"), "not this one");
createFile(root.resolve("Foo.java"), "this one");
@Ignore
// Docs suggest that Files.walk/find should search depth first, but behaviour seems
// to be OS dependent in practice. Windows ci on azure looks to search depth first, linux
// and mac find the root file. Fortunately we don't actually care about the behaviour in this case
// either file might be the one the user intended
public void findsFileInWrongPackageBeforeRoot() throws Exception {
createFile(root.resolve("com/example/other/Foo.java"), "this one");
createFile(root.resolve("Foo.java"), "not this one");
Optional<Reader> actual = testee.locate(singletonList("com.example.Foo"), "Foo.java");
assertThat(content(actual)).isEqualTo("this one");
}
Expand Down Expand Up @@ -111,6 +120,16 @@ public void doesNotErrorWhenRootDoesNotExist() {
.doesNotThrowAnyException();
}

private String findFor(String clazz, String file) throws Exception {
return findFor(singletonList(clazz), file);
}

private String findFor(Collection<String> classes, String file) throws Exception {
Optional<Reader> actual = testee.locate(classes, file);
return content(actual);
}


private void createFile(Path file, String content) throws IOException {
if (file.getParent() != null) {
Files.createDirectories(file.getParent());
Expand Down

0 comments on commit a92baf3

Please sign in to comment.