Search in sources :

Example 1 with PrintSettings

use of org.mockito.internal.reporting.PrintSettings in project powermock by powermock.

the class ToStringGenerator method generate.

public String generate(Object mock, Method method, Object[] arguments) {
    final List<ArgumentMatcher> matcherList = ArgumentsProcessor.argumentsToMatchers(arguments);
    final PrintSettings printSettings = new PrintSettings();
    MatchersPrinter matchersPrinter = new MatchersPrinter();
    String methodName = Whitebox.getUnproxyType(mock).getName() + "." + method.getName();
    String invocation = methodName + matchersPrinter.getArgumentsLine(matcherList, printSettings);
    if (printSettings.isMultiline() || (!matcherList.isEmpty() && invocation.length() > Whitebox.<Integer>getInternalState(PrintSettings.class, "MAX_LINE_LENGTH"))) {
        return methodName + matchersPrinter.getArgumentsBlock(matcherList, printSettings);
    } else {
        return invocation;
    }
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) PrintSettings(org.mockito.internal.reporting.PrintSettings) MatchersPrinter(org.mockito.internal.matchers.text.MatchersPrinter)

Example 2 with PrintSettings

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

the class MatchersPrinterTest method shouldGetArgumentsLine.

@Test
public void shouldGetArgumentsLine() {
    String line = printer.getArgumentsLine((List) Arrays.asList(new Equals(1), new Equals(2)), new PrintSettings());
    assertEquals("(1, 2);", line);
}
Also used : TestCase.assertEquals(junit.framework.TestCase.assertEquals) PrintSettings(org.mockito.internal.reporting.PrintSettings) Test(org.junit.Test)

Example 3 with PrintSettings

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

the class MatchersPrinterTest method shouldGetArgumentsBlock.

@Test
public void shouldGetArgumentsBlock() {
    String line = printer.getArgumentsBlock((List) Arrays.asList(new Equals(1), new Equals(2)), new PrintSettings());
    assertEquals("(\n    1,\n    2\n);", line);
}
Also used : TestCase.assertEquals(junit.framework.TestCase.assertEquals) PrintSettings(org.mockito.internal.reporting.PrintSettings) Test(org.junit.Test)

Aggregations

PrintSettings (org.mockito.internal.reporting.PrintSettings)3 TestCase.assertEquals (junit.framework.TestCase.assertEquals)2 Test (org.junit.Test)2 ArgumentMatcher (org.mockito.ArgumentMatcher)1 MatchersPrinter (org.mockito.internal.matchers.text.MatchersPrinter)1