-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AdditionalMatchers.and() and or() swap matcher order (#3335)
Fixes #3331
- Loading branch information
1 parent
f3821ff
commit 12cef84
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
43 changes: 43 additions & 0 deletions
43
src/test/java/org/mockitousage/matchers/AdditionalMatcherTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 AdditionalMatcherTest { | ||
|
||
interface Foo { | ||
int doSomeThing(Object param); | ||
} | ||
|
||
@Test | ||
public void shouldMatchArgumentsSequentiallyWithAnd() { | ||
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 shouldMatchArgumentsSequentiallyWithOr() { | ||
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); | ||
} | ||
} |