Created
June 10, 2023 09:12
-
-
Save avmohan/63aef344037af4f2a09344e9428b4a29 to your computer and use it in GitHub Desktop.
Mockito argument matcher that satisfies assertj assertions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
import org.assertj.core.matcher.AssertionMatcher; | |
import org.mockito.hamcrest.MockitoHamcrest; | |
public class CustomMatchers { | |
private CustomMatchers() {} | |
public static <T> T argSatisfying(Consumer<T> assertions) { | |
return MockitoHamcrest.argThat( | |
new AssertionMatcher<T>() { | |
public void assertion(T actual) throws AssertionError { | |
assertions.accept(actual); | |
} | |
}); | |
} | |
} | |
// verify(aMock).aMethod(argThat(actual -> assertThat(actual).containsExactlyInAnyOrder(aValue, anotherValue))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment