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;
11import org.mockito.stubbing.ValidableAnswer;
12
13import static org.mockito.internal.exceptions.Reporter.onlyVoidMethodsCanBeSetToDoNothing;
14
15public class DoesNothing implements Answer<Object>, ValidableAnswer, Serializable {
16
17    private static final long serialVersionUID = 4840880517740698416L;
18
19    private static final DoesNothing SINGLETON = new DoesNothing();
20
21    private DoesNothing() {}
22
23    public static DoesNothing doesNothing(){
24        return SINGLETON;
25    }
26
27    @Override
28    public Object answer(InvocationOnMock invocation){
29        return null;
30    }
31
32    @Override
33    public void validateFor(InvocationOnMock invocation) {
34        if (!new InvocationInfo(invocation).isVoid()) {
35            throw onlyVoidMethodsCanBeSetToDoNothing();
36        }
37    }
38}
39