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.MinSizeCheck;
22:
23: /**
24: * @author Sebastian Thomschke
25: */
26: public class MinSizeTest extends AbstractContraintsTest {
27: public void testMinSize() {
28: final MinSizeCheck check = new MinSizeCheck();
29: super .testCheck(check);
30: assertTrue(check.isSatisfied(null, null, null, null));
31:
32: check.setMin(2);
33: assertEquals(2, check.getMin());
34:
35: assertFalse(check.isSatisfied(null, new Object[0], null, null));
36: assertFalse(check.isSatisfied(null, new Object[1], null, null));
37: assertTrue(check.isSatisfied(null, new Object[2], null, null));
38: assertTrue(check.isSatisfied(null, new Object[3], null, null));
39:
40: List<Object> list = new ArrayList<Object>();
41: assertFalse(check.isSatisfied(null, list, null, null));
42: list.add(1);
43: assertFalse(check.isSatisfied(null, list, null, null));
44: list.add(2);
45: assertTrue(check.isSatisfied(null, list, null, null));
46: list.add(3);
47: assertTrue(check.isSatisfied(null, list, null, null));
48:
49: Set<Object> set = new HashSet<Object>();
50: assertFalse(check.isSatisfied(null, set, null, null));
51: set.add(1);
52: assertFalse(check.isSatisfied(null, set, null, null));
53: set.add(2);
54: assertTrue(check.isSatisfied(null, set, null, null));
55: set.add(3);
56: assertTrue(check.isSatisfied(null, set, null, null));
57:
58: Map<Object, Object> map = new HashMap<Object, Object>();
59: assertFalse(check.isSatisfied(null, map, null, null));
60: map.put(1, 1);
61: assertFalse(check.isSatisfied(null, map, null, null));
62: map.put(2, 2);
63: assertTrue(check.isSatisfied(null, map, null, null));
64: map.put(3, 3);
65: assertTrue(check.isSatisfied(null, map, null, null));
66:
67: assertFalse(check.isSatisfied(null, "bla", null, null));
68: }
69: }
|