KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > constraint > StringContainsTest


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

3 package test.jmock.core.constraint;
4
5 import org.jmock.core.constraint.StringContains;
6
7
8 public class StringContainsTest extends AbstractConstraintsTest
9 {
10     static final String JavaDoc EXCERPT = "EXCERPT";
11
12     StringContains stringContains;
13
14     public void setUp() {
15         stringContains = new StringContains(EXCERPT);
16     }
17
18     public void testEvaluatesToTrueIfArgumentContainsSpecifiedSubstring() {
19         assertTrue("should be true if excerpt at beginning",
20                    stringContains.eval(EXCERPT + "END"));
21         assertTrue("should be true if excerpt at end",
22                    stringContains.eval("START" + EXCERPT));
23         assertTrue("should be true if excerpt in middle",
24                    stringContains.eval("START" + EXCERPT + "END"));
25         assertTrue("should be true if excerpt is repeated",
26                    stringContains.eval(EXCERPT + EXCERPT));
27
28         assertFalse("should not be true if excerpt is not in string",
29                     stringContains.eval("Something else"));
30         assertFalse("should not be true if part of excerpt is in string",
31                     stringContains.eval(EXCERPT.substring(1)));
32     }
33
34     public void testEvaluatesToTrueIfArgumentIsEqualToSubstring() {
35         assertTrue("should be true if excerpt is entire string",
36                    stringContains.eval(EXCERPT));
37     }
38 }
39
Popular Tags