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.MockitoCore; 8 import org.mockito.quality.Strictness; 9 import org.mockito.stubbing.Answer; 10 import org.mockito.stubbing.LenientStubber; 11 import org.mockito.stubbing.OngoingStubbing; 12 import org.mockito.stubbing.Stubber; 13 14 public class DefaultLenientStubber implements LenientStubber { 15 16 private final static MockitoCore MOCKITO_CORE = new MockitoCore(); 17 18 @Override doThrow(Throwable... toBeThrown)19 public Stubber doThrow(Throwable... toBeThrown) { 20 return stubber().doThrow(toBeThrown); 21 } 22 23 @Override doThrow(Class<? extends Throwable> toBeThrown)24 public Stubber doThrow(Class<? extends Throwable> toBeThrown) { 25 return stubber().doThrow(toBeThrown); 26 } 27 28 @Override doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>... nextToBeThrown)29 public Stubber doThrow(Class<? extends Throwable> toBeThrown, Class<? extends Throwable>... nextToBeThrown) { 30 return stubber().doThrow(toBeThrown, nextToBeThrown); 31 } 32 33 @Override doAnswer(Answer answer)34 public Stubber doAnswer(Answer answer) { 35 return stubber().doAnswer(answer); 36 } 37 38 @Override doNothing()39 public Stubber doNothing() { 40 return stubber().doNothing(); 41 } 42 43 @Override doReturn(Object toBeReturned)44 public Stubber doReturn(Object toBeReturned) { 45 return stubber().doReturn(toBeReturned); 46 } 47 48 @Override doReturn(Object toBeReturned, Object... nextToBeReturned)49 public Stubber doReturn(Object toBeReturned, Object... nextToBeReturned) { 50 return stubber().doReturn(toBeReturned, nextToBeReturned); 51 } 52 53 @Override doCallRealMethod()54 public Stubber doCallRealMethod() { 55 return stubber().doCallRealMethod(); 56 } 57 58 @Override when(T methodCall)59 public <T> OngoingStubbing<T> when(T methodCall) { 60 OngoingStubbingImpl<T> ongoingStubbing = (OngoingStubbingImpl) MOCKITO_CORE.when(methodCall); 61 ongoingStubbing.setStrictness(Strictness.LENIENT); 62 return ongoingStubbing; 63 } 64 stubber()65 private static Stubber stubber() { 66 return MOCKITO_CORE.stubber(Strictness.LENIENT); 67 } 68 } 69