forked from mockito/mockito
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue mockito#1222 and mockito#584
Adds a new method varargsAsArray(...) that indicates that the varargs should be matched/captured as a single array rather than separate values.
- Loading branch information
1 parent
e10c540
commit 590eed7
Showing
8 changed files
with
199 additions
and
25 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
51 changes: 51 additions & 0 deletions
51
src/main/java/org/mockito/internal/matchers/TreatVarargsAsArray.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,51 @@ | ||
/* | ||
* Copyright (c) 2017 Mockito contributors | ||
* This program is made available under the terms of the MIT License. | ||
*/ | ||
package org.mockito.internal.matchers; | ||
|
||
import org.mockito.ArgumentMatcher; | ||
import org.mockito.internal.matchers.text.MatcherToString; | ||
import java.io.Serializable; | ||
|
||
/** | ||
*/ | ||
public class TreatVarargsAsArray<T> | ||
implements ArgumentMatcher<T>, ContainsExtraTypeInfo, CapturesArguments, Serializable { | ||
|
||
private final ArgumentMatcher<T> delegate; | ||
|
||
public TreatVarargsAsArray(ArgumentMatcher<T> delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public boolean matches(T argument) { | ||
return delegate.matches(argument); | ||
} | ||
|
||
@Override | ||
public void captureFrom(Object argument) { | ||
if (delegate instanceof CapturesArguments) { | ||
((CapturesArguments) delegate).captureFrom(argument); | ||
} | ||
} | ||
|
||
@Override | ||
public String toStringWithType() { | ||
if (delegate instanceof ContainsExtraTypeInfo) { | ||
return ((ContainsExtraTypeInfo) delegate).toStringWithType(); | ||
} | ||
return toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "varargsAsArray(" + MatcherToString.toString(delegate) + ")"; | ||
} | ||
|
||
@Override | ||
public boolean typeMatches(Object target) { | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,5 @@ public interface ArgumentMatcherStorage { | |
|
||
void reset(); | ||
|
||
ArgumentMatcher<?> popMatcher(); | ||
} |
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
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