Skip to content

Commit

Permalink
refactored some TODOs
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : svn%3Aaa2aecf3-ea3e-0410-9d70-716747e7c967/trunk%40327
  • Loading branch information
mockitoguy committed Jan 22, 2008
1 parent 25f1eaf commit c11da9a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/org/mockito/exceptions/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public void unfinishedVerificationException() {
));
}

//TODO Printable for those strings?
public void wantedDiffersFromActual(String wanted, String actual, HasStackTrace actualInvocationStackTrace) {
public void wantedDiffersFromActual(Printable wanted, Printable actual, HasStackTrace actualInvocationStackTrace) {
WantedDiffersFromActual cause1 = new WantedDiffersFromActual(join(
"Actual invocation:",
actual.toString()
Expand All @@ -124,7 +123,6 @@ public void wantedButNotInvoked(Printable wanted) {
));
}

//TODO previous and previousStackTrace should be the same object
public void wantedButNotInvokedInOrder(Printable wanted, Printable previous, HasStackTrace previousStackTrace) {
WantedAnywhereAfterFollowingInteraction cause = new WantedAnywhereAfterFollowingInteraction(join(
"Wanted anywhere AFTER following interaction:",
Expand Down
16 changes: 12 additions & 4 deletions src/org/mockito/internal/invocation/InvocationsPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.mockito.internal.invocation;

import org.mockito.exceptions.Printable;

public class InvocationsPrinter {

private final String wanted;
Expand All @@ -19,11 +21,17 @@ public InvocationsPrinter(InvocationMatcher wantedInvocation, Invocation actualI
}
}

public String printWanted() {
return wanted;
public Printable getWanted() {
return new Printable() {
public String toString() {
return wanted;
}};
}

public String printActual() {
return actual;
public Printable getActual() {
return new Printable() {
public String toString() {
return actual;
}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void verify(List<Invocation> invocations, InvocationMatcher wanted, Verif
private void reportMissingInvocationError(InvocationMatcher wanted, Invocation similar) {
if (similar != null) {
InvocationsPrinter printer = new InvocationsPrinter(wanted, similar);
reporter.wantedDiffersFromActual(printer.printWanted(), printer.printActual(), similar.getStackTrace());
reporter.wantedDiffersFromActual(printer.getWanted(), printer.getActual(), similar.getStackTrace());
} else {
reporter.wantedButNotInvoked(wanted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

public class VerifyingRecorder {

//TODO don't like LL coz it's too slow :)
private LinkedList<Invocation> registeredInvocations = new LinkedList<Invocation>();

private final List<? extends Verifier> verifiers;
Expand Down
2 changes: 2 additions & 0 deletions test/org/mockito/MockitoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class MockitoTest extends RequiresValidState {
//TODO I want to have ruby script that will collect all java code from examples in javadoc/documentation
// and create a test case that I can manually fix and run and make sure examples are valid

//TODO check if performace can be tweaked (e.g: LL -> AL)

@Test
public void shouldRemoveStubbableFromProgressAfterStubbing() {
List mock = Mockito.mock(List.class);
Expand Down
12 changes: 6 additions & 6 deletions test/org/mockito/internal/invocation/InvocationsPrinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public void shouldPrintWantedAndActualInvocation() throws Exception {
Invocation differentMethod = new InvocationBuilder().differentMethod().toInvocation();
InvocationsPrinter printer = new InvocationsPrinter(simpleMethod, differentMethod);

assertEquals("Object.simpleMethod()", printer.printWanted());
assertEquals("Object.differentMethod()", printer.printActual());
assertEquals("Object.simpleMethod()", printer.getWanted().toString());
assertEquals("Object.differentMethod()", printer.getActual().toString());
}

class Super {
Expand All @@ -42,8 +42,8 @@ public void shouldPrintSequenceNumbersWhenMatchesButMocksDifferent() throws Exce

assertEquals(invocationOne.toString(), invocationTwo.toString());

assertEquals("Object.test(class java.lang.Object)", printer.printWanted());
assertEquals("Object.test(class java.lang.String)", printer.printActual());
assertEquals("Object.test(class java.lang.Object)", printer.getWanted().toString());
assertEquals("Object.test(class java.lang.String)", printer.getActual().toString());
}

class Dummy {
Expand All @@ -62,7 +62,7 @@ public void shouldPrintTypesWhenMockArgsAndMethodNameMatchButMethodNotEqual() th

assertEquals(invocationOne.toString(), invocationTwo.toString());

assertEquals("Object.test(class [Ljava.lang.Object;)", printer.printWanted());
assertEquals("Object.test(class [Ljava.lang.String;)", printer.printActual());
assertEquals("Object.test(class [Ljava.lang.Object;)", printer.getWanted().toString());
assertEquals("Object.test(class [Ljava.lang.String;)", printer.getActual().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ public void shouldReportWantedInvocationDiffersFromActual() {

verifier.verify(invocations, wanted, VerificationModeImpl.atLeastOnce());

assertEquals(wanted.toString(), reporterStub.wanted);
assertEquals(actualInvocation.toString(), reporterStub.actual);
assertEquals(wanted.toString(), reporterStub.wanted.toString());
assertEquals(actualInvocation.toString(), reporterStub.actual.toString());
assertSame(actualInvocation.getStackTrace(), reporterStub.actualInvocationStackTrace);
}

class ReporterStub extends Reporter {
private Object wanted;
private String actual;
private Object actual;
private HasStackTrace actualInvocationStackTrace;
@Override public void wantedButNotInvoked(Printable wanted) {
this.wanted = wanted;
}
@Override public void wantedDiffersFromActual(String wanted, String actual, HasStackTrace actualInvocationStackTrace) {
@Override public void wantedDiffersFromActual(Printable wanted, Printable actual, HasStackTrace actualInvocationStackTrace) {
this.wanted = wanted;
this.actual = actual;
this.actualInvocationStackTrace = actualInvocationStackTrace;
Expand Down

0 comments on commit c11da9a

Please sign in to comment.