KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Is the value the same object as another value?
10  */

11 public class IsSame implements Constraint
12 {
13     private Object JavaDoc object;
14
15     /**
16      * Creates a new instance of IsSame
17      *
18      * @param object The predicate evaluates to true only when the argument is
19      * this object.
20      */

21     public IsSame( Object JavaDoc object ) {
22         this.object = object;
23     }
24
25     public boolean eval( Object JavaDoc arg ) {
26         return arg == object;
27     }
28
29     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
30         buffer.append("same(");
31         if (object == null) {
32             buffer.append("null");
33         } else {
34             buffer.append("<");
35             buffer.append(object);
36             buffer.append(">");
37         }
38         buffer.append(")");
39
40         return buffer;
41     }
42 }
43
Popular Tags