01: package org.andromda.translation.ocl.validation;
02:
03: import junit.framework.TestCase;
04: import org.apache.commons.collections.Transformer;
05:
06: import java.util.ArrayList;
07: import java.util.Collection;
08:
09: /**
10: * Tests the OCLCollections
11: *
12: * @author Chad Brandon
13: */
14: public class OCLCollectionsTest extends TestCase {
15:
16: /**
17: * Constructor for OCLCollectionsTest.
18: *
19: * @param name the test name
20: */
21: public OCLCollectionsTest(String name) {
22: super (name);
23: }
24:
25: /**
26: * Tests isUnique
27: */
28: public void testIsUnique() {
29: Collection collection = new ArrayList();
30: OCLCollectionsTestObject testObject = new OCLCollectionsTestObject();
31: testObject.setPropertyOne("propertyOne");
32: collection.add(testObject);
33: testObject = new OCLCollectionsTestObject();
34: testObject.setPropertyOne("propertyOneAgain");
35: collection.add(testObject);
36: assertEquals(2, collection.size());
37: assertTrue(OCLCollections.isUnique(collection,
38: new Transformer() {
39: public Object transform(Object object) {
40: return OCLIntrospector.invoke(object,
41: "propertyOne");
42: }
43:
44: }));
45: assertTrue(OCLCollections.isUnique((Object) collection,
46: new Transformer() {
47: public Object transform(Object object) {
48: return OCLIntrospector.invoke(object,
49: "propertyOne");
50: }
51:
52: }));
53: testObject = new OCLCollectionsTestObject();
54: testObject.setPropertyOne("propertyOne");
55: collection.add(testObject);
56: assertEquals(3, collection.size());
57: assertFalse(OCLCollections.isUnique(collection,
58: new Transformer() {
59: public Object transform(Object object) {
60: return OCLIntrospector.invoke(object,
61: "propertyOne");
62: }
63:
64: }));
65: assertFalse(OCLCollections.isUnique((Object) collection,
66: new Transformer() {
67: public Object transform(Object object) {
68: return OCLIntrospector.invoke(object,
69: "propertyOne");
70: }
71:
72: }));
73: collection.remove(testObject);
74: assertEquals(2, collection.size());
75: assertTrue(OCLCollections.isUnique(collection,
76: new Transformer() {
77: public Object transform(Object object) {
78: return OCLIntrospector.invoke(object,
79: "propertyOne");
80: }
81:
82: }));
83: assertTrue(OCLCollections.isUnique((Object) collection,
84: new Transformer() {
85: public Object transform(Object object) {
86: return OCLIntrospector.invoke(object,
87: "propertyOne");
88: }
89:
90: }));
91: }
92:
93: }
|