1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.stubbing.answers;
6
7import java.io.Serializable;
8
9import org.mockito.invocation.InvocationOnMock;
10import org.mockito.stubbing.Answer;
11
12/**
13 * Optional Answer that adds partial mocking support
14 * <p>
15 * {@link Answer} can be used to define the return values of unstubbed invocations.
16 * <p>
17 * This implementation can be helpful when working with legacy code.
18 * When this implementation is used, unstubbed methods will delegate to the real implementation.
19 * This is a way to create a partial mock object that calls real methods by default.
20 * <p>
21 * As usual you are going to read <b>the partial mock warning</b>:
22 * Object oriented programming is more less tackling complexity by dividing the complexity into separate, specific, SRPy objects.
23 * How does partial mock fit into this paradigm? Well, it just doesn't...
24 * Partial mock usually means that the complexity has been moved to a different method on the same object.
25 * In most cases, this is not the way you want to design your application.
26 * <p>
27 * However, there are rare cases when partial mocks come handy:
28 * dealing with code you cannot change easily (3rd party interfaces, interim refactoring of legacy code etc.)
29 * However, I wouldn't use partial mocks for new, test-driven & well-designed code.
30 * <p>
31 */
32public class CallsRealMethods implements Answer<Object>, Serializable {
33    private static final long serialVersionUID = 9057165148930624087L;
34
35    public Object answer(InvocationOnMock invocation) throws Throwable {
36        return invocation.callRealMethod();
37    }
38}