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.io.Serializable; 9 import java.util.regex.Pattern; 10 11 import org.hamcrest.Description; 12 import org.mockito.ArgumentMatcher; 13 14 public class Find extends ArgumentMatcher<String> implements Serializable { 15 16 private static final long serialVersionUID = 8895781429480404872L; 17 private final String regex; 18 Find(String regex)19 public Find(String regex) { 20 this.regex = regex; 21 } 22 matches(Object actual)23 public boolean matches(Object actual) { 24 return actual != null && Pattern.compile(regex).matcher((String) actual).find(); 25 } 26 describeTo(Description description)27 public void describeTo(Description description) { 28 description.appendText("find(\"" + regex.replaceAll("\\\\", "\\\\\\\\") + "\")"); 29 } 30 }