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 StringStartsWith extends SubstringMatcher {
012    public StringStartsWith(String substring) {
013        super(substring);
014    }
015
016    @Override
017    protected boolean evalSubstringOf(String s) {
018        return s.startsWith(substring);
019    }
020
021    @Override
022    protected String relationship() {
023        return "starting with";
024    }
025
026    /**
027     * Creates a matcher that matches if the examined {@link String} starts with the specified
028     * {@link String}.
029     * <p/>
030     * For example:
031     * <pre>assertThat("myStringOfNote", startsWith("my"))</pre>
032     * 
033     * @param prefix
034     *      the substring that the returned matcher will expect at the start of any examined string
035     */
036    @Factory
037    public static Matcher<String> startsWith(String prefix) {
038        return new StringStartsWith(prefix);
039    }
040
041}