KickJava   Java API By Example, From Geeks To Geeks.

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


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 whether the value is an instance of a class.
10  */

11 public class IsInstanceOf implements Constraint
12 {
13     private Class JavaDoc theClass;
14
15     /**
16      * Creates a new instance of IsInstanceOf
17      *
18      * @param theClass The predicate evaluates to true for instances of this class
19      * or one of its subclasses.
20      */

21     public IsInstanceOf( Class JavaDoc theClass ) {
22         this.theClass = theClass;
23     }
24
25     public boolean eval( Object JavaDoc arg ) {
26         return theClass.isInstance(arg);
27     }
28
29     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
30         return buffer.append("an instance of ")
31                 .append(theClass.getName());
32     }
33 }
34
Popular Tags