1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.matchers; 6 7 import org.junit.Test; 8 import org.mockito.internal.matchers.text.MatchersPrinter; 9 import org.mockito.internal.reporting.PrintSettings; 10 import org.mockitoutil.TestBase; 11 12 import java.util.Arrays; 13 import java.util.List; 14 15 import static org.junit.Assert.assertEquals; 16 17 @SuppressWarnings("unchecked") 18 public class MatchersPrinterTest extends TestBase { 19 20 private final MatchersPrinter printer = new MatchersPrinter(); 21 22 @Test shouldGetArgumentsLine()23 public void shouldGetArgumentsLine() { 24 String line = printer.getArgumentsLine((List) Arrays.asList(new Equals(1), new Equals(2)), new PrintSettings()); 25 assertEquals("(1, 2);", line); 26 } 27 28 @Test shouldGetArgumentsBlock()29 public void shouldGetArgumentsBlock() { 30 String line = printer.getArgumentsBlock((List) Arrays.asList(new Equals(1), new Equals(2)), new PrintSettings()); 31 assertEquals("(\n 1,\n 2\n);", line); 32 } 33 34 @Test shouldDescribeTypeInfoOnlyMarkedMatchers()35 public void shouldDescribeTypeInfoOnlyMarkedMatchers() { 36 //when 37 String line = printer.getArgumentsLine((List) Arrays.asList(new Equals(1L), new Equals(2)), PrintSettings.verboseMatchers(1)); 38 //then 39 assertEquals("(1L, (Integer) 2);", line); 40 } 41 42 @Test shouldDescribeStringMatcher()43 public void shouldDescribeStringMatcher() { 44 //when 45 String line = printer.getArgumentsLine((List) Arrays.asList(new Equals(1L), new Equals("x")), PrintSettings.verboseMatchers(1)); 46 //then 47 assertEquals("(1L, (String) \"x\");", line); 48 } 49 50 @Test shouldGetVerboseArgumentsInBlock()51 public void shouldGetVerboseArgumentsInBlock() { 52 //when 53 String line = printer.getArgumentsBlock((List) Arrays.asList(new Equals(1L), new Equals(2)), PrintSettings.verboseMatchers(0, 1)); 54 //then 55 assertEquals("(\n (Long) 1L,\n (Integer) 2\n);", line); 56 } 57 58 @Test shouldGetVerboseArgumentsEvenIfSomeMatchersAreNotVerbose()59 public void shouldGetVerboseArgumentsEvenIfSomeMatchersAreNotVerbose() { 60 //when 61 String line = printer.getArgumentsLine((List) Arrays.asList(new Equals(1L), NotNull.NOT_NULL), PrintSettings.verboseMatchers(0)); 62 //then 63 assertEquals("((Long) 1L, notNull());", line); 64 } 65 } 66