forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes mockito#3331 : AdditionalMatchers.and() and or() swap matcher o…
…rder
- Loading branch information
1 parent
fb9ff6d
commit 757a415
Showing
2 changed files
with
58 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
56 changes: 56 additions & 0 deletions
56
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,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 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); | ||
} | ||
} |