KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jmock > core > testsupport > MockConstraint


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

3 package test.jmock.core.testsupport;
4
5 import junit.framework.Assert;
6 import org.jmock.core.Constraint;
7 import org.jmock.core.Verifiable;
8
9
10 public class MockConstraint extends Assert implements Constraint, Verifiable
11 {
12     private String JavaDoc description;
13     private Object JavaDoc expectedArg;
14     private boolean result;
15     private boolean wasChecked = false;
16
17
18     public MockConstraint( String JavaDoc description ) {
19         this(description, null, true);
20         wasChecked = true;
21     }
22
23     public MockConstraint( String JavaDoc description, Object JavaDoc expectedArg, boolean result ) {
24         this.description = description;
25         this.expectedArg = expectedArg;
26         this.result = result;
27     }
28
29     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
30         return buffer.append(description);
31     }
32
33     public boolean eval( Object JavaDoc arg ) {
34         assertSame("Should be expected argument", expectedArg, arg);
35         wasChecked = true;
36         return result;
37     }
38
39     public void verify() {
40         assertTrue(description + " should have been checked", wasChecked);
41     }
42 }
43
Popular Tags