• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockito.internal.stubbing;
6 
7 import org.mockito.internal.stubbing.answers.DoesNothing;
8 import org.mockito.internal.stubbing.answers.ThrowsException;
9 import org.mockito.stubbing.Answer;
10 import org.mockito.stubbing.VoidMethodStubbable;
11 
12 public class VoidMethodStubbableImpl<T> implements VoidMethodStubbable<T> {
13     private final T mock;
14     private InvocationContainerImpl invocationContainerImpl;
15 
VoidMethodStubbableImpl(T mock, InvocationContainerImpl invocationContainerImpl)16     public VoidMethodStubbableImpl(T mock, InvocationContainerImpl invocationContainerImpl) {
17         this.mock = mock;
18         this.invocationContainerImpl = invocationContainerImpl;
19     }
20 
toThrow(Throwable throwable)21     public VoidMethodStubbable<T> toThrow(Throwable throwable) {
22         invocationContainerImpl.addAnswerForVoidMethod(new ThrowsException(throwable));
23         return this;
24     }
25 
toReturn()26     public VoidMethodStubbable<T> toReturn() {
27         invocationContainerImpl.addAnswerForVoidMethod(new DoesNothing());
28         return this;
29     }
30 
toAnswer(Answer<?> answer)31     public VoidMethodStubbable<T> toAnswer(Answer<?> answer) {
32         invocationContainerImpl.addAnswerForVoidMethod(answer);
33         return this;
34     }
35 
on()36     public T on() {
37         return mock;
38     }
39 }