01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.test.constraints;
13:
14: import net.sf.oval.constraint.InstanceOfAnyCheck;
15:
16: /**
17: * @author Sebastian Thomschke
18: */
19: public class InstanceOfAnyTest extends AbstractContraintsTest {
20: public static class ClassA implements InterfaceA {
21: //
22: }
23:
24: public static class ClassB implements InterfaceA, InterfaceB {
25: //
26: }
27:
28: public interface InterfaceA {
29: //
30: }
31:
32: public interface InterfaceB {
33: //
34: }
35:
36: public void testInstanceOf() {
37: final InstanceOfAnyCheck check = new InstanceOfAnyCheck();
38: super .testCheck(check);
39: assertTrue(check.isSatisfied(null, null, null, null));
40:
41: check.setTypes(InterfaceA.class);
42: assertEquals(InterfaceA.class, check.getTypes()[0]);
43:
44: assertTrue(check.isSatisfied(null, new ClassA(), null, null));
45: assertTrue(check.isSatisfied(null, new ClassB(), null, null));
46: assertFalse(check.isSatisfied(null, "bla", null, null));
47:
48: check
49: .setTypes(new Class[] { InterfaceA.class,
50: InterfaceB.class });
51: assertEquals(InterfaceA.class, check.getTypes()[0]);
52: assertEquals(InterfaceB.class, check.getTypes()[1]);
53:
54: assertTrue(check.isSatisfied(null, new ClassA(), null, null));
55: assertTrue(check.isSatisfied(null, new ClassB(), null, null));
56: assertFalse(check.isSatisfied(null, "bla", null, null));
57: }
58: }
|