aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/junit/internal/matchers/StringContains.java
blob: e5f53345d5eba7b71ac3c0ac12e2a670b2b612db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*  Copyright (c) 2000-2006 hamcrest.org
 */
package org.junit.internal.matchers;

import org.hamcrest.Factory;
import org.hamcrest.Matcher;

/**
 * Tests if the argument is a string that contains a substring.
 */
public class StringContains extends SubstringMatcher {
    public StringContains(String substring) {
        super(substring);
    }

    @Override
	protected boolean evalSubstringOf(String s) {
        return s.indexOf(substring) >= 0;
    }

    @Override
	protected String relationship() {
        return "containing";
    }

    @Factory
    public static Matcher<String> containsString(String substring) {
        return new StringContains(substring);
    }

}