Search in sources :

Example 1 with ReturnsEmptyValues

use of org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues in project mockito by mockito.

the class InvocationContainerImplTest method should_tell_if_has_invocation_for_potential_stubbing.

@Test
public void should_tell_if_has_invocation_for_potential_stubbing() throws Exception {
    container.setInvocationForPotentialStubbing(new InvocationBuilder().toInvocationMatcher());
    assertTrue(container.hasInvocationForPotentialStubbing());
    container.addAnswer(new ReturnsEmptyValues(), null);
    assertFalse(container.hasInvocationForPotentialStubbing());
}
Also used : ReturnsEmptyValues(org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 2 with ReturnsEmptyValues

use of org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues in project mockito by mockito.

the class InvocationContainerImplTest method should_tell_if_has_invocation_for_potential_stubbing_stub_only.

@Test
public void should_tell_if_has_invocation_for_potential_stubbing_stub_only() throws Exception {
    containerStubOnly.setInvocationForPotentialStubbing(new InvocationBuilder().toInvocationMatcher());
    assertTrue(containerStubOnly.hasInvocationForPotentialStubbing());
    containerStubOnly.addAnswer(new ReturnsEmptyValues(), null);
    assertFalse(containerStubOnly.hasInvocationForPotentialStubbing());
}
Also used : ReturnsEmptyValues(org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues) InvocationBuilder(org.mockito.internal.invocation.InvocationBuilder) Test(org.junit.Test)

Example 3 with ReturnsEmptyValues

use of org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues in project mockito by mockito.

the class ClonesArguments method answer.

@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
    Object[] arguments = invocation.getArguments();
    for (int i = 0; i < arguments.length; i++) {
        Object from = arguments[i];
        if (from != null) {
            if (from.getClass().isArray()) {
                int len = Array.getLength(from);
                Object newInstance = Array.newInstance(from.getClass().getComponentType(), len);
                for (int j = 0; j < len; ++j) {
                    Array.set(newInstance, j, Array.get(from, j));
                }
                arguments[i] = newInstance;
            } else {
                Instantiator instantiator = Plugins.getInstantiatorProvider().getInstantiator(null);
                Object newInstance = instantiator.newInstance(from.getClass());
                new LenientCopyTool().copyToRealObject(from, newInstance);
                arguments[i] = newInstance;
            }
        }
    }
    return new ReturnsEmptyValues().answer(invocation);
}
Also used : ReturnsEmptyValues(org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues) Instantiator(org.mockito.creation.instance.Instantiator) LenientCopyTool(org.mockito.internal.util.reflection.LenientCopyTool)

Aggregations

ReturnsEmptyValues (org.mockito.internal.stubbing.defaultanswers.ReturnsEmptyValues)3 Test (org.junit.Test)2 InvocationBuilder (org.mockito.internal.invocation.InvocationBuilder)2 Instantiator (org.mockito.creation.instance.Instantiator)1 LenientCopyTool (org.mockito.internal.util.reflection.LenientCopyTool)1