Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental flexible matching of varargs
Not intended for check-in but demonstrates that we can match varargs flexibly. See #1224 Can we follow down this path and fix problem #1222 and #584 in the way the API is most convenient to use?
- Loading branch information
1 parent
c2d8f02
commit c5cae24
Showing
3 changed files
with
73 additions
and
27 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
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
30 changes: 30 additions & 0 deletions
30
src/test/java/org/mockitousage/matchers/FlexibleVarargsTest.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,30 @@ | ||
package org.mockitousage.matchers; | ||
|
||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockitousage.IMethods; | ||
import org.mockitoutil.TestBase; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* Documents work on the #1222 | ||
*/ | ||
public class FlexibleVarargsTest extends TestBase { | ||
|
||
@Mock IMethods mock; | ||
|
||
@Test | ||
public void verifies_varargs_flexibly() throws Exception { | ||
mock.mixedVarargs("1", "2", "3"); | ||
|
||
//traditional verify with varargs, same number of args | ||
verify(mock).mixedVarargs(any(), eq("2"), eq("3")); | ||
|
||
//new matching, using an array | ||
verify(mock).mixedVarargs(any(), eq(new String[] {"2", "3"})); | ||
verify(mock).mixedVarargs(any(), (String[]) any()); | ||
} | ||
} |