2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.testutils.mockito;
10 import com.google.common.annotations.Beta;
11 import java.io.Serializable;
12 import org.mockito.Mockito;
13 import org.mockito.internal.stubbing.answers.ThrowsException;
14 import org.mockito.invocation.InvocationOnMock;
15 import org.mockito.stubbing.Answer;
18 * Mockito Answer which for un-stubbed methods throws an
19 * UnstubbedMethodException (instead of Mockito's default of returning null).
25 * import static ...testutils.mockito.MoreAnswers.exception;
27 * Mockito.mock(YourInterface.class, exception())
30 * @see Mockito#mock(Class, Answer)
32 * @see ThrowsException
34 * @author Michael Vorburger
37 public final class ThrowsMethodExceptionAnswer implements Answer<Object>, Serializable {
38 private static final long serialVersionUID = -7316574192253912318L;
39 static final ThrowsMethodExceptionAnswer INSTANCE = new ThrowsMethodExceptionAnswer();
41 private ThrowsMethodExceptionAnswer() {
46 public Void answer(final InvocationOnMock invocation) {
47 throw new UnstubbedMethodException(invocation.getMethod());
50 Object readResolve() {