1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 6 package org.mockito.internal.matchers; 7 8 import java.util.regex.Pattern; 9 import org.junit.Test; 10 import org.mockito.ArgumentMatcher; 11 import org.mockitoutil.TestBase; 12 13 import static org.junit.Assert.assertEquals; 14 15 public class MatchersToStringTest extends TestBase { 16 17 @Test sameToStringWithString()18 public void sameToStringWithString() { 19 assertEquals("same(\"X\")", new Same("X").toString()); 20 } 21 22 @Test nullToString()23 public void nullToString() { 24 assertEquals("isNull()", Null.NULL.toString()); 25 } 26 27 @Test notNullToString()28 public void notNullToString() { 29 assertEquals("notNull()", NotNull.NOT_NULL.toString()); 30 } 31 32 @Test anyToString()33 public void anyToString() { 34 assertEquals("<any>", Any.ANY.toString()); 35 } 36 37 @Test sameToStringWithChar()38 public void sameToStringWithChar() { 39 assertEquals("same('x')", new Same('x').toString()); 40 } 41 42 @Test sameToStringWithObject()43 public void sameToStringWithObject() { 44 Object o = new Object() { 45 @Override 46 public String toString() { 47 return "X"; 48 } 49 }; 50 assertEquals("same(X)", new Same(o).toString()); 51 } 52 53 @Test equalsToStringWithString()54 public void equalsToStringWithString() { 55 assertEquals("\"X\"", new Equals("X").toString()); 56 57 } 58 59 @Test equalsToStringWithChar()60 public void equalsToStringWithChar() { 61 assertEquals("'x'", new Equals('x').toString()); 62 } 63 64 @Test equalsToStringWithObject()65 public void equalsToStringWithObject() { 66 Object o = new Object() { 67 @Override 68 public String toString() { 69 return "X"; 70 } 71 }; 72 assertEquals("X", new Equals(o).toString()); 73 } 74 75 @Test orToString()76 public void orToString() { 77 ArgumentMatcher<?> m1=new Equals(1); 78 ArgumentMatcher<?> m2=new Equals(2); 79 assertEquals("or(1, 2)", new Or(m1,m2).toString()); 80 } 81 82 @Test notToString()83 public void notToString() { 84 assertEquals("not(1)", new Not(new Equals(1)).toString()); 85 } 86 87 @Test andToString()88 public void andToString() { 89 ArgumentMatcher<?> m1=new Equals(1); 90 ArgumentMatcher<?> m2=new Equals(2); 91 assertEquals("and(1, 2)", new And(m1,m2).toString()); 92 } 93 94 @Test startsWithToString()95 public void startsWithToString() { 96 assertEquals("startsWith(\"AB\")", new StartsWith("AB").toString()); 97 } 98 99 @Test endsWithToString()100 public void endsWithToString() { 101 assertEquals("endsWith(\"AB\")", new EndsWith("AB").toString()); 102 } 103 104 @Test containsToString()105 public void containsToString() { 106 assertEquals("contains(\"AB\")", new Contains("AB").toString()); 107 } 108 109 @Test findToString()110 public void findToString() { 111 assertEquals("find(\"\\\\s+\")", new Find("\\s+").toString()); 112 } 113 114 @Test matchesToString()115 public void matchesToString() { 116 assertEquals("matches(\"\\\\s+\")", new Matches("\\s+").toString()); 117 assertEquals("matches(\"\\\\s+\")", new Matches(Pattern.compile("\\s+")).toString()); 118 } 119 120 } 121