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 java.util.ArrayList;
15: import java.util.HashMap;
16: import java.util.HashSet;
17: import java.util.List;
18: import java.util.Map;
19: import java.util.Set;
20:
21: import net.sf.oval.constraint.SizeCheck;
22:
23: /**
24: * @author Sebastian Thomschke
25: */
26: public class SizeTest extends AbstractContraintsTest {
27: public void testSize() {
28: final SizeCheck check = new SizeCheck();
29: super .testCheck(check);
30: assertTrue(check.isSatisfied(null, null, null, null));
31:
32: check.setMin(2);
33: check.setMax(3);
34: assertEquals(2, check.getMin());
35: assertEquals(3, check.getMax());
36:
37: assertFalse(check.isSatisfied(null, new Object[0], null, null));
38: assertFalse(check.isSatisfied(null, new Object[1], null, null));
39: assertTrue(check.isSatisfied(null, new Object[2], null, null));
40: assertTrue(check.isSatisfied(null, new Object[3], null, null));
41: assertFalse(check.isSatisfied(null, new Object[4], null, null));
42:
43: List<Object> list = new ArrayList<Object>();
44: assertFalse(check.isSatisfied(null, list, null, null));
45: list.add(1);
46: assertFalse(check.isSatisfied(null, list, null, null));
47: list.add(2);
48: assertTrue(check.isSatisfied(null, list, null, null));
49: list.add(3);
50: assertTrue(check.isSatisfied(null, list, null, null));
51: list.add(4);
52: assertFalse(check.isSatisfied(null, list, null, null));
53:
54: Set<Object> set = new HashSet<Object>();
55: assertFalse(check.isSatisfied(null, set, null, null));
56: set.add(1);
57: assertFalse(check.isSatisfied(null, set, null, null));
58: set.add(2);
59: assertTrue(check.isSatisfied(null, set, null, null));
60: set.add(3);
61: assertTrue(check.isSatisfied(null, set, null, null));
62: set.add(4);
63: assertFalse(check.isSatisfied(null, set, null, null));
64:
65: Map<Object, Object> map = new HashMap<Object, Object>();
66: assertFalse(check.isSatisfied(null, map, null, null));
67: map.put(1, 1);
68: assertFalse(check.isSatisfied(null, map, null, null));
69: map.put(2, 2);
70: assertTrue(check.isSatisfied(null, map, null, null));
71: map.put(3, 3);
72: assertTrue(check.isSatisfied(null, map, null, null));
73: map.put(4, 4);
74: assertFalse(check.isSatisfied(null, map, null, null));
75:
76: assertFalse(check.isSatisfied(null, "bla", null, null));
77: }
78: }
|