Search in sources :

Example 1 with Equals

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");
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Invocation(org.mockito.invocation.Invocation) CapturingMatcher(org.mockito.internal.matchers.CapturingMatcher) Test(org.junit.Test)

Example 2 with Equals

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]);
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.Test)

Example 3 with Equals

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);
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Test(org.junit.Test)

Example 4 with Equals

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);
}
Also used : Equals(org.mockito.internal.matchers.Equals) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Test(org.junit.Test)

Example 5 with Equals

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);
}
Also used : Equals(org.mockito.internal.matchers.Equals) Test(org.junit.Test)

Aggregations

Equals (org.mockito.internal.matchers.Equals)9 Test (org.junit.Test)7 TestCase.assertEquals (junit.framework.TestCase.assertEquals)6 ArgumentMatcher (org.mockito.ArgumentMatcher)2 CapturingMatcher (org.mockito.internal.matchers.CapturingMatcher)2 Invocation (org.mockito.invocation.Invocation)2 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1