Search in sources :

Example 1 with SmartPrinter

use of org.mockito.internal.reporting.SmartPrinter in project mockito by mockito.

the class MissingInvocationChecker method checkMissingInvocation.

public static void checkMissingInvocation(List<Invocation> invocations, MatchableInvocation wanted) {
    List<Invocation> actualInvocations = findInvocations(invocations, wanted);
    if (!actualInvocations.isEmpty()) {
        return;
    }
    Invocation similar = findSimilarInvocation(invocations, wanted);
    if (similar == null) {
        throw wantedButNotInvoked(wanted, invocations);
    }
    Integer[] indexesOfSuspiciousArgs = getSuspiciouslyNotMatchingArgsIndexes(wanted.getMatchers(), similar.getArguments());
    SmartPrinter smartPrinter = new SmartPrinter(wanted, similar, indexesOfSuspiciousArgs);
    throw argumentsAreDifferent(smartPrinter.getWanted(), smartPrinter.getActual(), similar.getLocation());
}
Also used : Invocation(org.mockito.invocation.Invocation) MatchableInvocation(org.mockito.invocation.MatchableInvocation) InvocationsFinder.findSimilarInvocation(org.mockito.internal.invocation.InvocationsFinder.findSimilarInvocation) SmartPrinter(org.mockito.internal.reporting.SmartPrinter)

Example 2 with SmartPrinter

use of org.mockito.internal.reporting.SmartPrinter in project mockito by mockito.

the class SmartPrinterTest method shouldPrintBothInMultilinesWhenFirstIsMulti.

@Test
public void shouldPrintBothInMultilinesWhenFirstIsMulti() {
    //when
    SmartPrinter printer = new SmartPrinter(multi, shortie.getInvocation());
    //then
    assertThat(printer.getWanted().toString()).contains("\n");
    assertThat(printer.getActual().toString()).contains("\n");
}
Also used : SmartPrinter(org.mockito.internal.reporting.SmartPrinter) Test(org.junit.Test)

Example 3 with SmartPrinter

use of org.mockito.internal.reporting.SmartPrinter in project mockito by mockito.

the class SmartPrinterTest method shouldPrintBothInSingleLineWhenBothAreShort.

@Test
public void shouldPrintBothInSingleLineWhenBothAreShort() {
    //when
    SmartPrinter printer = new SmartPrinter(shortie, shortie.getInvocation());
    //then
    assertThat(printer.getWanted().toString()).doesNotContain("\n");
    assertThat(printer.getActual().toString()).doesNotContain("\n");
}
Also used : SmartPrinter(org.mockito.internal.reporting.SmartPrinter) Test(org.junit.Test)

Example 4 with SmartPrinter

use of org.mockito.internal.reporting.SmartPrinter in project mockito by mockito.

the class SmartPrinterTest method shouldPrintBothInMultilinesWhenBothAreMulti.

@Test
public void shouldPrintBothInMultilinesWhenBothAreMulti() {
    //when
    SmartPrinter printer = new SmartPrinter(multi, multi.getInvocation());
    //then
    assertThat(printer.getWanted().toString()).contains("\n");
    assertThat(printer.getActual().toString()).contains("\n");
}
Also used : SmartPrinter(org.mockito.internal.reporting.SmartPrinter) Test(org.junit.Test)

Example 5 with SmartPrinter

use of org.mockito.internal.reporting.SmartPrinter in project mockito by mockito.

the class SmartPrinterTest method shouldPrintBothInMultilinesWhenSecondIsMulti.

@Test
public void shouldPrintBothInMultilinesWhenSecondIsMulti() {
    //when
    SmartPrinter printer = new SmartPrinter(shortie, multi.getInvocation());
    //then
    assertThat(printer.getWanted().toString()).contains("\n");
    assertThat(printer.getActual().toString()).contains("\n");
}
Also used : SmartPrinter(org.mockito.internal.reporting.SmartPrinter) Test(org.junit.Test)

Aggregations

SmartPrinter (org.mockito.internal.reporting.SmartPrinter)5 Test (org.junit.Test)4 InvocationsFinder.findSimilarInvocation (org.mockito.internal.invocation.InvocationsFinder.findSimilarInvocation)1 Invocation (org.mockito.invocation.Invocation)1 MatchableInvocation (org.mockito.invocation.MatchableInvocation)1