diff --git a/src/main/java/org/mockito/internal/progress/ArgumentMatcherStorageImpl.java b/src/main/java/org/mockito/internal/progress/ArgumentMatcherStorageImpl.java index dbbc0279ce..a853f23c97 100644 --- a/src/main/java/org/mockito/internal/progress/ArgumentMatcherStorageImpl.java +++ b/src/main/java/org/mockito/internal/progress/ArgumentMatcherStorageImpl.java @@ -42,8 +42,8 @@ public List pullLocalizedMatchers() { public void reportAnd() { assertStateFor("And(?)", TWO_SUB_MATCHERS); - ArgumentMatcher m1 = popMatcher(); ArgumentMatcher m2 = popMatcher(); + ArgumentMatcher m1 = popMatcher(); reportMatcher(new And(m1, m2)); } @@ -52,8 +52,8 @@ public void reportAnd() { public void reportOr() { assertStateFor("Or(?)", TWO_SUB_MATCHERS); - ArgumentMatcher m1 = popMatcher(); ArgumentMatcher m2 = popMatcher(); + ArgumentMatcher m1 = popMatcher(); reportMatcher(new Or(m1, m2)); } diff --git a/src/test/java/org/mockitousage/matchers/ArgumentMatcherTest.java b/src/test/java/org/mockitousage/matchers/ArgumentMatcherTest.java new file mode 100644 index 0000000000..3db5b545b1 --- /dev/null +++ b/src/test/java/org/mockitousage/matchers/ArgumentMatcherTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 Mockito contributors + * This program is made available under the terms of the MIT License. + */ +package org.mockitousage.matchers; + +import org.junit.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.AdditionalMatchers.and; +import static org.mockito.AdditionalMatchers.or; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ArgumentMatcherTest { + + interface Foo { + int doSomeThing(Object param); + } + + @Test + public void shouldAndMatchSequentially() { + Foo foo = mock(Foo.class); + + when( + foo.doSomeThing( + and( + any(String.class), + argThat(String::isEmpty) + ))) + .thenReturn(1); + + assertNotEquals(foo.doSomeThing(1), 1); + } + + @Test + public void shouldOrMatchSequentially() { + Foo foo = mock(Foo.class); + + when( + foo.doSomeThing( + or( + any(Integer.class), + and( + any(Object.class), + argThat(String::isEmpty) + ) + ))) + .thenReturn(1); + + assertEquals(foo.doSomeThing(1), 1); + } +}