1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockito.internal.verification;
6
7import static org.assertj.core.api.Assertions.assertThat;
8
9import org.junit.Before;
10import org.junit.Test;
11import org.mockito.Mock;
12import org.mockito.internal.invocation.InvocationMatcher;
13import org.mockito.internal.reporting.SmartPrinter;
14import org.mockitousage.IMethods;
15import org.mockitoutil.TestBase;
16
17public class SmartPrinterTest extends TestBase {
18
19    private InvocationMatcher multi;
20    private InvocationMatcher shortie;
21    @Mock private IMethods mock;
22
23    @Before
24    public void setup() throws Exception {
25        mock.varargs("first very long argument", "second very long argument", "another very long argument");
26        multi = new InvocationMatcher(getLastInvocation());
27
28        mock.varargs("short arg");
29        shortie = new InvocationMatcher(getLastInvocation());
30    }
31
32    @Test
33    public void shouldPrintBothInMultilinesWhenFirstIsMulti() {
34        //when
35        SmartPrinter printer = new SmartPrinter(multi, shortie.getInvocation());
36
37        //then
38        assertThat(printer.getWanted().toString()).contains("\n");
39        assertThat(printer.getActual().toString()).contains("\n");
40    }
41
42    @Test
43    public void shouldPrintBothInMultilinesWhenSecondIsMulti() {
44        //when
45        SmartPrinter printer = new SmartPrinter(shortie, multi.getInvocation());
46
47        //then
48        assertThat(printer.getWanted().toString()).contains("\n");
49        assertThat(printer.getActual().toString()).contains("\n");
50    }
51
52    @Test
53    public void shouldPrintBothInMultilinesWhenBothAreMulti() {
54        //when
55        SmartPrinter printer = new SmartPrinter(multi, multi.getInvocation());
56
57        //then
58        assertThat(printer.getWanted().toString()).contains("\n");
59        assertThat(printer.getActual().toString()).contains("\n");
60    }
61
62    @Test
63    public void shouldPrintBothInSingleLineWhenBothAreShort() {
64        //when
65        SmartPrinter printer = new SmartPrinter(shortie, shortie.getInvocation());
66
67        //then
68        assertThat(printer.getWanted().toString()).doesNotContain("\n");
69        assertThat(printer.getActual().toString()).doesNotContain("\n");
70    }
71}
72