Если вам не нужно проверять, не являются ли файлы непустыми, Files :: fileNamesIn может пригодиться. Вы можете сделать что-то вроде:
assertThat(Files.filesNamesIn(dir, /* recursive */ true)).contains(
basePath + "/maven-metadata-local.xml",
basePath + "/1.0/install_should_not_fail-1.0.jar",
basePath + "/1.0/install_should_not_fail-1.0.pom",
basePath + "/1.0/_remote.repositories")
В противном случае вы можете изменить этот шаблон в свое собственное утверждение. Например, вот утверждение, которое проверяет, что данные пути представляют непустые, читаемые файлы внутри каталога:
public class MyAssertions extends Assertions {
public static MyFileAssert assertThat(File actual) {
return MyFileAssert.assertThat(actual);
}
}
public class MyFileAssert extends AbstractFileAssert<MyFileAssert> {
public MyFileAssert(File actual) {
super(actual, MyFileAssert.class);
}
public static MyFileAssert assertThat(File actual) {
return new MyFileAssert(actual);
}
public MyFileAssert containsReadableNonEmptyFiles(String... paths) {
isDirectory();
List<String> nonExistent = new ArrayList<>();
List<String> nonFiles = new ArrayList<>();
List<String> nonReadable = new ArrayList<>();
List<String> empty = new ArrayList<>();
for (String path : paths) {
File file = new File(actual, path);
if (!file.exists()) {
nonExistent.add(path);
continue;
}
if (!file.isFile()) {
nonFiles.add(path);
continue;
}
if (!file.canRead()) {
nonReadable.add(path);
continue;
}
if (file.length() == 0) {
empty.add(path);
}
}
if (!(nonExistent.isEmpty() && nonFiles.isEmpty() && nonReadable.isEmpty() && empty.isEmpty())) {
StringBuilder failMessage = new StringBuilder()
.append("Expected directory '")
.append(actual)
.append("' to contain the following readable, non-empty files:\n");
for (String path : paths) {
failMessage.append(" ")
.append(path)
.append("\n");
}
if (!nonExistent.isEmpty()) {
failMessage.append("The following files don't exist:\n");
for (String path : nonExistent) {
failMessage.append(" ")
.append(path)
.append("\n");
}
}
// The rest left out for brevity.
failWithMessage(failMessage.toString());
}
return this;
}
}
Пример использования приведенного выше примера:
assertThat(install_should_not_fail).containsReadableNonEmptyFiles(
"maven-metadata-local.xml",
"1.0/install_should_not_fail-1.0.jar",
"1.0/install_should_not_fail-1.0.pom",
"1.0/_remote.repositories")
Вы можете узнать больше о пользовательских утверждениях AssertJ здесь .