use of org.mockito.internal.matchers.Equals in project mockito by mockito.
the class InvocationMatcherTest method should_capture_varargs_as_vararg.
@Test
public void should_capture_varargs_as_vararg() throws Exception {
//given
mock.mixedVarargs(1, "a", "b");
Invocation invocation = getLastInvocation();
CapturingMatcher m = new CapturingMatcher();
InvocationMatcher invocationMatcher = new InvocationMatcher(invocation, Arrays.<ArgumentMatcher>asList(new Equals(1), m));
//when
invocationMatcher.captureArgumentsFrom(invocation);
//then
Assertions.assertThat(m.getAllValues()).containsExactly("a", "b");
}
use of org.mockito.internal.matchers.Equals in project mockito by mockito.
the class ArgumentMatchingToolTest method shouldFindSuspiciousMatchers.
@Test
public void shouldFindSuspiciousMatchers() {
// given
Equals matcherInt20 = new Equals(20);
Long longPretendingAnInt = 20L;
// when
List<ArgumentMatcher> matchers = (List) Arrays.asList(new Equals(10), matcherInt20);
Integer[] suspicious = ArgumentMatchingTool.getSuspiciouslyNotMatchingArgsIndexes(matchers, new Object[] { 10, longPretendingAnInt });
// then
assertEquals(1, suspicious.length);
assertEquals(new Integer(1), suspicious[0]);
}
use of org.mockito.internal.matchers.Equals in project mockito by mockito.
the class ArgumentMatchingToolTest method shouldNotFindSuspiciousMatchersWhenTypesAreTheSame.
@Test
public void shouldNotFindSuspiciousMatchersWhenTypesAreTheSame() {
// given
Equals matcherWithBadDescription = new Equals(20) {
public String toString() {
return "10";
}
};
Integer argument = 10;
// when
Integer[] suspicious = ArgumentMatchingTool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(matcherWithBadDescription), new Object[] { argument });
// then
assertEquals(0, suspicious.length);
}
use of org.mockito.internal.matchers.Equals in project mockito by mockito.
the class ArgumentMatchingToolTest method shouldWorkFineWhenGivenArgIsNull.
@Test
public void shouldWorkFineWhenGivenArgIsNull() {
// when
Integer[] suspicious = ArgumentMatchingTool.getSuspiciouslyNotMatchingArgsIndexes((List) Arrays.asList(new Equals(20)), new Object[] { null });
// then
assertEquals(0, suspicious.length);
}
use of org.mockito.internal.matchers.Equals in project mockito by mockito.
the class MatcherApplicationStrategyTest method shouldMatchAnyVarargEvenIfOneOfTheArgsIsNull.
@Test
public void shouldMatchAnyVarargEvenIfOneOfTheArgsIsNull() {
// given
invocation = mixedVarargs(null, null, "2");
matchers = asList(new Equals(null), ANY);
// when
getMatcherApplicationStrategyFor(invocation, matchers).forEachMatcherAndArgument(recordAction);
// then
recordAction.assertContainsExactly(new Equals(null), ANY, ANY);
}
Aggregations