Skip to content

Commit

Permalink
remove unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-ot committed Apr 27, 2023
1 parent 84eb447 commit 91cc46a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/mockito/ThrowingConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.function.Consumer;

@SuppressWarnings("FunctionalInterfaceMethodChanged")
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {
@Override
Expand Down
39 changes: 13 additions & 26 deletions src/test/java/org/mockitousage/matchers/MatchersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.mockito.Mockito.anyShort;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.contains;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.endsWith;
import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.isNotNull;
Expand All @@ -47,6 +48,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -60,6 +62,7 @@
import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.mockito.exceptions.verification.opentest4j.ArgumentsAreDifferent;
import org.mockitousage.IMethods;
import org.mockitousage.stubbing.StubbingUsingDoReturnTest;
import org.mockitoutil.TestBase;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -647,9 +650,17 @@ public void assertArg_matcher_fails_when_assertion_fails() throws Exception {
}

@Test
public void assertArg_matcher_fails_when_assertion_fails_with_ioException() throws Exception {
public void assertArg_matcher_can_accept_throwing_consumer() throws Exception {
mock.oneArg("hello");

try {
verify(mock).simpleMethod(assertArg((Object o) -> mock.throwsIOException(0)));
verify(mock)
.oneArg(
assertArg(
(String it) -> {
assertEquals("not-hello", it);
doThrow(new IOException()).when(mock).throwsIOException(0);
}));
fail("Should throw an exception");
} catch (ComparisonFailure e) {
// do nothing
Expand Down Expand Up @@ -683,28 +694,4 @@ public void can_verify_on_mock_after_assert_arg() throws Exception {

verify(mock).oneArg("hello");
}

@Test
public void can_invoke_method_on_mock_after_assert_arg_with_ioException() throws Exception {
try {
verify(mock).simpleMethod(assertArg((Object o) -> mock.throwsIOException(0)));
fail("Should throw an exception");
} catch (ComparisonFailure e) {
// do nothing
}

mock.oneArg("hello");
}

@Test
public void can_verify_on_mock_after_assert_arg_with_ioException() throws Exception {
try {
verify(mock).simpleMethod(assertArg((Object o) -> mock.throwsIOException(0)));
fail("Should throw an exception");
} catch (ComparisonFailure e) {
// do nothing
}

verify(mock).oneArg("hello");
}
}

0 comments on commit 91cc46a

Please sign in to comment.