KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > constraint > StringContains


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.core.constraint;
4
5 import org.jmock.core.Constraint;
6
7
8 /**
9  * Tests if the argument is a string that contains a substring.
10  */

11 public class StringContains implements Constraint
12 {
13     private String JavaDoc substring;
14
15     public StringContains( String JavaDoc substring ) {
16         this.substring = substring;
17     }
18
19     public boolean eval( Object JavaDoc o ) {
20         return o instanceof String JavaDoc && ((String JavaDoc)o).indexOf(substring) >= 0;
21     }
22
23
24     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
25         return buffer.append("a string containing \"")
26                 .append(substring)
27                 .append("\"");
28     }
29 }
30
Popular Tags