--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ </parent>
+
+ <!-- FIXME: remove this once parent is bumped -->
+ <version>0.6.0-SNAPSHOT</version>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>mockito-configuration</artifactId>
+ <description>Default mockito configuration</description>
+ <packaging>jar</packaging><!-- not needed in OSGi -->
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <dependencies>
+ <!-- all those dependencies will be in test scope as mockito-configuration should be referenced as test scope dependency -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import org.mockito.exceptions.base.MockitoException;
+import org.mockito.internal.invocation.InvocationsFinder;
+import org.mockito.internal.verification.api.VerificationData;
+import org.mockito.invocation.Invocation;
+import org.mockito.verification.VerificationMode;
+
+import java.util.List;
+
+/**
+ * Verifier that extracts arguments from actual invocation. Useful when deeper validation of arguments is needed.
+ *
+ */
+public class ArgumentsExtractorVerifier implements VerificationMode {
+ private Object[] arguments;
+
+ @Override
+ public void verify(VerificationData data) {
+ InvocationsFinder finder = new InvocationsFinder();
+ List<Invocation> actualInvocations = finder.findInvocations(data.getAllInvocations(), data.getWanted());
+ if (actualInvocations.size() != 1) {
+ throw new MockitoException("This verifier can only be used with 1 invocation, got " + actualInvocations.size());
+ }
+ Invocation invocation = actualInvocations.get(0);
+ arguments = invocation.getArguments();
+ invocation.markVerified();
+
+ }
+ public Object[] getArguments(){
+ return arguments;
+ }
+ }
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import org.mockito.stubbing.Answer;
+
+/**
+ * Configuration customization for Mockito. Change default answer to {@link ThrowsUnstubbedMethodException}.
+ */
+public class MockitoConfiguration extends DefaultMockitoConfiguration {
+
+ @Override
+ public Answer<Object> getDefaultAnswer() {
+ return new ThrowsUnstubbedMethodException();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import java.io.Serializable;
+
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * Answer that throws {@link UnstubbedMethodException}.
+ */
+public class ThrowsUnstubbedMethodException implements Answer<Object>, Serializable {
+ private static final long serialVersionUID = 1L;
+
+ public ThrowsUnstubbedMethodException() {
+ }
+
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Throwable t = new UnstubbedMethodException(invocation.toString() + " was not stubbed");
+ throw t;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+
+/**
+ * Exception to be thrown on unstubbed method call.
+ */
+public class UnstubbedMethodException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public UnstubbedMethodException(String message) {
+ super(message);
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class ArgumentsExtractorVerifierTest {
+
+ @Mock
+ List<String> mockedList;
+
+ @Test
+ public void test() {
+ MockitoAnnotations.initMocks(this);
+ doReturn(true).when(this.mockedList).add(any(String.class));
+ final String argument = "something";
+ this.mockedList.add(argument);
+ // retrieve argument
+ final ArgumentsExtractorVerifier argumentsExtractorVerifier = new ArgumentsExtractorVerifier();
+ verify(this.mockedList, argumentsExtractorVerifier).add(any(String.class));
+ assertArrayEquals(new Object[] { argument }, argumentsExtractorVerifier.getArguments());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.mockito.configuration;
+
+import static org.junit.Assert.*;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class DefaultAnswerTest {
+
+ @Test
+ public void testAnswering() throws IOException {
+ Closeable mock = Mockito.mock(Closeable.class);
+ try {
+ mock.close();
+ fail();
+ } catch (UnstubbedMethodException e) {
+ assertEquals("closeable.close(); was not stubbed", e.getMessage());
+ }
+ }
+
+
+
+}
<slf4j.version>1.7.2</slf4j.version>\r
<guava.version>14.0.1</guava.version>\r
<xtend.version>2.4.3</xtend.version>\r
- <groovy.version>2.1.6</groovy.version>\r
+ <groovy.version>2.1.6</groovy.version>\r
+ <mockito.version>1.9.5</mockito.version>\r
</properties>\r
\r
<scm>\r
<module>yang</module>\r
<module>code-generator</module>\r
<module>model</module>\r
- <module>restconf</module>\r
+ <module>restconf</module>\r
+ <module>mockito-configuration</module>\r
<!-- module>third-party</module -->\r
</modules>\r
\r
<dependency>\r
<groupId>org.mockito</groupId>\r
<artifactId>mockito-all</artifactId>\r
- <version>1.9.5</version>\r
+ <version>${mockito.version}</version>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.mockito</groupId>\r
+ <artifactId>mockito-core</artifactId>\r
+ <version>${mockito.version}</version>\r
<scope>test</scope>\r
</dependency>\r
\r