Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ ij_groovy_method_parameters_right_paren_on_new_line = false
ij_groovy_method_parameters_wrap = off
ij_groovy_modifier_list_wrap = false
ij_groovy_names_count_to_use_import_on_demand = 999999
ij_groovy_packages_to_use_import_on_demand = empty
ij_groovy_parameter_annotation_wrap = off
ij_groovy_parentheses_expression_new_line_after_left_paren = false
ij_groovy_parentheses_expression_right_paren_on_new_line = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
*/
package io.github.ascopes.jct.assertions;

import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
import static io.github.ascopes.jct.utils.IterableUtils.combineOneOrMore;
import static io.github.ascopes.jct.utils.IterableUtils.requireNonNullValues;
import static java.util.Objects.requireNonNull;
import static java.util.function.Predicate.not;
import static org.assertj.core.api.Assertions.assertThat;

import io.github.ascopes.jct.containers.PackageContainerGroup;
import io.github.ascopes.jct.repr.LocationRepresentation;
import io.github.ascopes.jct.utils.StringUtils;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.assertj.core.api.AbstractPathAssert;
import org.jspecify.annotations.Nullable;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.assertj.core.api.AbstractPathAssert;
import org.jspecify.annotations.Nullable;

import static io.github.ascopes.jct.utils.IoExceptionUtils.uncheckedIo;
import static io.github.ascopes.jct.utils.IterableUtils.combineOneOrMore;
import static io.github.ascopes.jct.utils.IterableUtils.requireNonNullValues;
import static io.github.ascopes.jct.utils.StringUtils.quoted;
import static io.github.ascopes.jct.utils.StringUtils.quotedIterable;
import static java.util.Objects.requireNonNull;
import static java.util.function.Predicate.not;
import static org.assertj.core.api.Assertions.assertThat;

/**
* Assertions for package container groups.
Expand Down Expand Up @@ -65,10 +67,11 @@ public PackageContainerGroupAssert(@Nullable PackageContainerGroup containerGrou
* @throws NullPointerException if any of the paths are null.
*/
public PackageContainerGroupAssert allFilesExist(String path, String... paths) {
requireNonNull(path, "path must not be null");
requireNonNull(path, "path");
requireNonNullValues(paths, "paths");

return allFilesExist(combineOneOrMore(path, paths));
allFilesExist(combineOneOrMore(path, paths));
return this;
}

/**
Expand All @@ -85,7 +88,12 @@ public PackageContainerGroupAssert allFilesExist(Iterable<String> paths) {

isNotNull();

assertThat(paths).allSatisfy(this::fileExists);
assertThat(paths)
.withFailMessage(
"Expected all paths in %s to exist but one or more did not",
quotedIterable(paths)
)
.allSatisfy(this::fileExists);
return this;
}

Expand Down Expand Up @@ -119,7 +127,7 @@ public ClassLoaderAssert classLoader() {
* @throws NullPointerException if any of the fragments are null.
*/
public PackageContainerGroupAssert fileDoesNotExist(String fragment, String... fragments) {
requireNonNull(fragment, "fragment must not be null");
requireNonNull(fragment, "fragment");
requireNonNullValues(fragments, "fragments");

isNotNull();
Expand All @@ -131,10 +139,10 @@ public PackageContainerGroupAssert fileDoesNotExist(String fragment, String... f
}

throw failure(
"Expected path \"%s\" to not exist in \"%s\" but it was found at \"%s\"",
userProvidedPath(combineOneOrMore(fragment, fragments)),
"Expected path %s to not exist in %s but it was found at %s",
quotedUserProvidedPath(combineOneOrMore(fragment, fragments)),
LocationRepresentation.getInstance().toStringOf(actual.getLocation()),
actualFile
quoted(actualFile)
);
}

Expand All @@ -160,7 +168,7 @@ public PackageContainerGroupAssert fileDoesNotExist(String fragment, String... f
*/

public AbstractPathAssert<?> fileExists(String fragment, String... fragments) {
requireNonNull(fragment, "fragment must not be null");
requireNonNull(fragment, "fragment");
requireNonNullValues(fragments, "fragments");

isNotNull();
Expand All @@ -175,11 +183,11 @@ public AbstractPathAssert<?> fileExists(String fragment, String... fragments) {
var expected = combineOneOrMore(fragment, fragments);
throw failure(StringUtils.resultNotFoundWithFuzzySuggestions(
fuzzySafePath(expected),
userProvidedPath(expected),
quotedUserProvidedPath(expected),
listAllUniqueFilesForAllContainers(),
this::fuzzySafePath,
this::userProvidedPath,
"path"
this::quotedUserProvidedPath,
"file with relative path"
));
}

Expand All @@ -198,11 +206,14 @@ private Set<Path> listAllUniqueFilesForAllContainers() {
.collect(Collectors.toSet());
}

private <T> String userProvidedPath(Iterable<T> parts) {
private <T> String quotedUserProvidedPath(Iterable<T> parts) {
return StreamSupport
.stream(parts.spliterator(), false)
.map(Objects::toString)
.collect(Collectors.joining("/"));
.collect(Collectors.collectingAndThen(
Collectors.joining("/"),
StringUtils::quoted
));
}

private <T> String fuzzySafePath(Iterable<T> parts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.mockito.ArgumentMatchers.argThat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import org.mockito.ArgumentMatcher;
Expand Down
Loading