1 /* 2 * Copyright (c) 2017 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 9 import static org.junit.Assert.assertFalse; 10 import static org.junit.Assert.assertTrue; 11 12 /** 13 * Tests for the Matchers that operate over strings 14 */ 15 public class StringMatchersTest { 16 @Test 17 public void startsWithString() { 18 assertTrue(new StartsWith("mockito").matches("mockito is here")); 19 } 20 21 @Test 22 public void doesNotStartWithString() { 23 assertFalse(new StartsWith("junit").matches("mockito is here")); 24 } 25 26 @Test 27 public void nullStartsWith() { 28 assertFalse(new StartsWith("java").matches(null)); 29 } 30 31 @Test 32 public void endsWithString() { 33 assertTrue(new EndsWith("mockito").matches("here is mockito")); 34 } 35 36 @Test 37 public void doesNotEndWithString() { 38 assertFalse(new EndsWith("junit").matches("here is mockito")); 39 } 40 41 @Test 42 public void nullEndsWith() { 43 assertFalse(new EndsWith("java").matches(null)); 44 } 45 46 @Test 47 public void containsString() { 48 assertTrue(new Contains("mockito").matches("****mockito****")); 49 } 50 51 @Test 52 public void stringDoesNotContain() { 53 assertFalse(new Contains("junit").matches("****mockito****")); 54 } 55 56 @Test 57 public void nullContainsNothing() { 58 assertFalse(new Contains("mockito").matches(null)); 59 } 60 61 @Test 62 public void matchesRegex() { 63 assertTrue(new Find("eleph.nt").matches("the elephant in the room")); 64 assertTrue(new Find("eleph.nt").matches("the elephInt in the room")); 65 } 66 67 @Test 68 public void doesNotMatchRegex() { 69 assertFalse(new Find("eleph.nt").matches("the otter in the room")); 70 } 71 72 @Test 73 public void nullDoesNotMatchRegex() { 74 assertFalse(new Find("eleph.nt").matches(null)); 75 } 76 77 } 78