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