001 /* Copyright (c) 2000-2006 hamcrest.org
002 */
003 package org.hamcrest.core;
004
005 import org.hamcrest.Factory;
006 import org.hamcrest.Matcher;
007
008 /**
009 * Tests if the argument is a string that contains a substring.
010 */
011 public class StringEndsWith extends SubstringMatcher {
012 public StringEndsWith(String substring) {
013 super(substring);
014 }
015
016 @Override
017 protected boolean evalSubstringOf(String s) {
018 return s.endsWith(substring);
019 }
020
021 @Override
022 protected String relationship() {
023 return "ending with";
024 }
025
026 /**
027 * Creates a matcher that matches if the examined {@link String} ends with the specified
028 * {@link String}.
029 * <p/>
030 * For example:
031 * <pre>assertThat("myStringOfNote", endsWith("Note"))</pre>
032 *
033 * @param suffix
034 * the substring that the returned matcher will expect at the end of any examined string
035 */
036 @Factory
037 public static Matcher<String> endsWith(String suffix) {
038 return new StringEndsWith(suffix);
039 }
040
041 }