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 3f8c230
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Optional<Reader> locate(Collection<String> classes, String fileName) {
.map(ClassName::fromString)
.map(ClassName::getPackage)
.distinct()
.map(c -> c.asJavaName().replace(".", File.separator) + File.separator + fileName)
.map(c -> toFileName(c, fileName))
.map(file -> root.resolve(file))
.filter(Files::exists)
.filter(Files::isRegularFile)
Expand All @@ -70,6 +70,13 @@ public Optional<Reader> locate(Collection<String> classes, String fileName) {
}
}

private String toFileName(ClassName packge, String fileName) {
if (packge.equals("")) {
return fileName;
}
return packge.asJavaName().replace(".", File.separator) + File.separator + fileName;
}

private Reader toReader(Path path) {
try {
return new InputStreamReader(new BufferedInputStream(Files.newInputStream(path)),
Expand Down
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 3f8c230

Please sign in to comment.