Skip to content

Instantly share code, notes, and snippets.

@divoxx
Created March 23, 2011 20:52
Show Gist options
  • Select an option

  • Save divoxx/883940 to your computer and use it in GitHub Desktop.

Select an option

Save divoxx/883940 to your computer and use it in GitHub Desktop.
package com.divoxx;
class Driver {
private Element element;
Driver(Element element) {
this.element = element;
}
void run() {
element.move();
element.move();
element.right();
element.move();
}
}
package com.divoxx;
import org.junit.Test;
import org.mockito.InOrder;
import static org.mockito.Mockito.*;
public class DriverTest {
@Test
public void bugReproduction() {
Element element = mock(Element.class);
Driver driver = new Driver(element);
InOrder ordered = inOrder(element);
driver.run();
ordered.verify(element).move();
ordered.verify(element).move();
ordered.verify(element).right();
ordered.verify(element).move();
}
}
package com.divoxx;
class Element {
void left() {}
void right() {}
void move() {}
}
DriverTest
com.divoxx.DriverTest
bugReproduction(com.divoxx.DriverTest)
org.mockito.exceptions.verification.VerificationInOrderFailure:
Verification in order failure:
element.move();
Wanted 1 time:
-> at com.divoxx.DriverTest.bugReproduction(DriverTest.java:17)
But was 3 times. Undesired invocation:
-> at com.divoxx.Driver.run(Driver.java:13)
at com.divoxx.DriverTest.bugReproduction(DriverTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment