Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Aug 18, 2020
1 parent eafed85 commit 5565967
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public WritableAssertionInfo() {
@Override
public String overridingErrorMessage() {
// at this point we can have only one of overridingErrorMessageSupplier or overridingErrorMessage
return overridingErrorMessageSupplier != null ? (String) overridingErrorMessageSupplier.get() : overridingErrorMessage;
return overridingErrorMessageSupplier != null ? overridingErrorMessageSupplier.get() : overridingErrorMessage;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/assertj/core/api/filter/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class Filters<E> {
final Iterable<E> initialIterable;
List<E> filteredIterable;

private final PropertyOrFieldSupport propertyOrFieldSupport = PropertyOrFieldSupport.EXTRACTION;
private static final PropertyOrFieldSupport PROPERTY_OR_FIELD_SUPPORT = PropertyOrFieldSupport.EXTRACTION;

/**
* The name of the property used for filtering.
Expand Down Expand Up @@ -224,7 +224,7 @@ public Filters<E> with(String propertyOrFieldName, Object propertyValue) {

/**
* Sets the name of the property used for filtering, it may be a nested property like
* <code>"adress.street.name"</code>.
* <code>"address.street.name"</code>.
* <p>
* The typical usage is to chain this call with a comparison method, for example :
* <pre><code class='java'> filter(employees).with("name").equalsTo("Alex").get();</code></pre>
Expand Down Expand Up @@ -270,7 +270,7 @@ public Filters<E> and(String propertyOrFieldName) {
public Filters<E> equalsTo(Object propertyValue) {
checkPropertyNameToFilterOnIsNotNull();
this.filteredIterable = filteredIterable.stream().filter(element -> {
Object propertyValueOfCurrentElement = propertyOrFieldSupport.getValueOf(propertyOrFieldNameToFilterOn, element);
Object propertyValueOfCurrentElement = PROPERTY_OR_FIELD_SUPPORT.getValueOf(propertyOrFieldNameToFilterOn, element);
return areEqual(propertyValueOfCurrentElement, propertyValue);
}).collect(toList());
return this;
Expand All @@ -291,7 +291,7 @@ public Filters<E> equalsTo(Object propertyValue) {
public Filters<E> notEqualsTo(Object propertyValue) {
checkPropertyNameToFilterOnIsNotNull();
this.filteredIterable = filteredIterable.stream().filter(element -> {
Object propertyValueOfCurrentElement = propertyOrFieldSupport.getValueOf(propertyOrFieldNameToFilterOn, element);
Object propertyValueOfCurrentElement = PROPERTY_OR_FIELD_SUPPORT.getValueOf(propertyOrFieldNameToFilterOn, element);
return !areEqual(propertyValueOfCurrentElement, propertyValue);
}).collect(toList());
return this;
Expand All @@ -316,7 +316,7 @@ private void checkPropertyNameToFilterOnIsNotNull() {
public Filters<E> in(Object... propertyValues) {
checkPropertyNameToFilterOnIsNotNull();
this.filteredIterable = filteredIterable.stream().filter(element -> {
Object propertyValueOfCurrentElement = propertyOrFieldSupport.getValueOf(propertyOrFieldNameToFilterOn, element);
Object propertyValueOfCurrentElement = PROPERTY_OR_FIELD_SUPPORT.getValueOf(propertyOrFieldNameToFilterOn, element);
return isItemInArray(propertyValueOfCurrentElement, propertyValues);
}).collect(toList());
return this;
Expand All @@ -336,7 +336,7 @@ public Filters<E> in(Object... propertyValues) {
public Filters<E> notIn(Object... propertyValues) {
checkPropertyNameToFilterOnIsNotNull();
this.filteredIterable = filteredIterable.stream().filter(element -> {
Object propertyValueOfCurrentElement = propertyOrFieldSupport.getValueOf(propertyOrFieldNameToFilterOn, element);
Object propertyValueOfCurrentElement = PROPERTY_OR_FIELD_SUPPORT.getValueOf(propertyOrFieldNameToFilterOn, element);
return !isItemInArray(propertyValueOfCurrentElement, propertyValues);
}).collect(toList());
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class DualValue {
}

DualValue(List<String> parentPath, String fieldName, Object actual, Object expected) {
this(fiedlPath(parentPath, fieldName), actual, expected);
this(fieldPath(parentPath, fieldName), actual, expected);
}

@Override
Expand Down Expand Up @@ -125,19 +125,19 @@ public boolean isActualFieldAnEmptyOptionalOfAnyType() {
}

private boolean isActualFieldAnEmptyOptional() {
return isActualFieldAnOptional() && ((Optional<?>) actual).isPresent() == false;
return isActualFieldAnOptional() && !((Optional<?>) actual).isPresent();
}

private boolean isActualFieldAnEmptyOptionalInt() {
return isActualFieldAnOptionalInt() && ((OptionalInt) actual).isPresent() == false;
return isActualFieldAnOptionalInt() && !((OptionalInt) actual).isPresent();
}

private boolean isActualFieldAnEmptyOptionalLong() {
return isActualFieldAnOptionalLong() && ((OptionalLong) actual).isPresent() == false;
return isActualFieldAnOptionalLong() && !((OptionalLong) actual).isPresent();
}

private boolean isActualFieldAnEmptyOptionalDouble() {
return isActualFieldAnOptionalDouble() && ((OptionalDouble) actual).isPresent() == false;
return isActualFieldAnOptionalDouble() && !((OptionalDouble) actual).isPresent();
}

public boolean isExpectedFieldAnOptional() {
Expand Down Expand Up @@ -208,7 +208,7 @@ private static boolean isContainer(Object o) {
isArray(o);
}

private static List<String> fiedlPath(List<String> parentPath, String fieldName) {
private static List<String> fieldPath(List<String> parentPath, String fieldName) {
List<String> fieldPath = newArrayList(parentPath);
fieldPath.add(fieldName);
return fieldPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void ignoreFieldsMatchingRegexes(String... regexes) {
* @param types the types of the object under test to ignore in the comparison.
*/
public void ignoreFieldsOfTypes(Class<?>... types) {
stream(types).map(type -> asWrapperIfPrimitiveType(type)).forEach(ignoredTypes::add);
stream(types).map(RecursiveComparisonConfiguration::asWrapperIfPrimitiveType).forEach(ignoredTypes::add);
}

private static Class<?> asWrapperIfPrimitiveType(Class<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void initDualValuesToCompare(Object actual, Object expected, List<String
// ignored fields according to recursiveComparisonConfiguration
Set<String> expectedFieldsNames = getFieldsNames(expected.getClass());
if (expectedFieldsNames.containsAll(nonIgnoredActualFieldsNames)) {
// we compare actual fields vs expected, ingoring expected additional fields
// we compare actual fields vs expected, ignoring expected additional fields
for (String nonIgnoredActualFieldName : nonIgnoredActualFieldsNames) {
DualValue fieldDualValue = new DualValue(parentPath, nonIgnoredActualFieldName,
COMPARISON.getSimpleValue(nonIgnoredActualFieldName, actual),
Expand All @@ -141,12 +141,10 @@ private void initDualValuesToCompare(Object actual, Object expected, List<String
// it occurs to unordered collection where we compare all possible combination of the collection elements recursively
// --
// remove visited values one by one, DualValue.equals correctly compare respective actual and expected fields by reference
visitedDualValues.forEach(visitedDualValue -> {
dualValuesToCompare.stream()
.filter(dualValueToCompare -> dualValueToCompare.equals(visitedDualValue))
.findFirst()
.ifPresent(dualValuesToCompare::remove);
});
visitedDualValues.forEach(visitedDualValue -> dualValuesToCompare.stream()
.filter(dualValueToCompare -> dualValueToCompare.equals(visitedDualValue))
.findFirst()
.ifPresent(dualValuesToCompare::remove));
}

private boolean mustCompareFieldsRecursively(boolean isRootObject, DualValue dualValue) {
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/assertj/core/condition/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private Join(Stream<? extends Condition<? super T>> stream) {
}

private static <T> T checkNotNullConditions(T conditions) {
return requireNonNull(conditions, conditionsIsNull());
return requireNonNull(conditions, "The given conditions should not be null");
}

/**
Expand All @@ -78,10 +78,6 @@ private static <T> T checkNotNullConditions(T conditions) {
*/
public abstract String descriptionPrefix();

private static String conditionsIsNull() {
return "The given conditions should not be null";
}

private static <T> T notNull(T condition) {
return requireNonNull(condition, "The given conditions should not have null entries");
}
Expand Down

0 comments on commit 5565967

Please sign in to comment.