Skip to content

Commit

Permalink
Fix #512 : filteredOn did not work with soft assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-costigliola committed Oct 31, 2015
1 parent 2b3335d commit 2f1bdb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/main/java/org/assertj/core/api/SoftProxies.java
Expand Up @@ -12,14 +12,14 @@
*/
package org.assertj.core.api;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
import static org.assertj.core.util.Arrays.array;

import java.lang.reflect.Method;
import java.util.List;

import static org.assertj.core.util.Arrays.array;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;

class SoftProxies {

Expand All @@ -42,14 +42,20 @@ private enum CollectErrorsOrCreateExtractedProxy implements CallbackFilter {
FILTER;

private static final int ERROR_COLLECTOR_INDEX = 0;
private static final int PROXIFY_EXTRACTING_INDEX = 1;
private static final int PROXIFY_EXTRACTING_OR_FILTEREDON_INDEX = 1;

@Override
public int accept(Method method) {
return isExtractingMethod(method) ? PROXIFY_EXTRACTING_INDEX : ERROR_COLLECTOR_INDEX;
return isExtractingMethod(method) || isFilteredOnMethod(method) ? PROXIFY_EXTRACTING_OR_FILTEREDON_INDEX
: ERROR_COLLECTOR_INDEX;
}

private boolean isExtractingMethod(Method method) {
return method.getName().toLowerCase().contains("extracting");
}

private boolean isFilteredOnMethod(Method method) {
return method.getName().contains("filteredOn");
}
}
}
10 changes: 5 additions & 5 deletions src/test/java/org/assertj/core/api/SoftAssertionsTest.java
Expand Up @@ -12,6 +12,7 @@
*/
package org.assertj.core.api;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down Expand Up @@ -503,18 +504,17 @@ public void should_collect_all_errors_when_using_flat_extracting() throws Except
@Test
public void should_collect_all_errors_when_using_filtering() throws Exception {

List<CartoonCharacter> characters = asList(homer, fred);

softly.assertThat(characters)
.overridingErrorMessage("error 1")
softly.assertThat(asList(homer, fred))
.filteredOn("name", "Homer Simpson")
.hasSize(10)
.isEmpty();

try {
softly.assertAll();
shouldHaveThrown(SoftAssertionError.class);
} catch (SoftAssertionError e) {
assertThat(e.getErrors()).containsExactly("error 1");
assertThat(e.getErrors()).containsOnly(format("%nExpected size:<10> but was:<1> in:%n<[CartoonCharacter [name=Homer Simpson]]>"),
format("%nExpecting empty but was:<[CartoonCharacter [name=Homer Simpson]]>"));
}
}

Expand Down

0 comments on commit 2f1bdb5

Please sign in to comment.