1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.domian.specification;
17
18
19 import org.junit.Test;
20
21 import static junit.framework.Assert.assertTrue;
22 import static net.sourceforge.domian.specification.SpecificationFactory.equalTo;
23 import static net.sourceforge.domian.specification.SpecificationFactory.hasSize;
24 import static net.sourceforge.domian.specification.SpecificationFactory.is;
25 import static net.sourceforge.domian.specification.SpecificationFactory.not;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.fail;
29
30
31 public class IsDisjointWith_OtherLeafSpecifications_Test {
32
33 CollectionSpecification<Integer> collectionWithTenElements =
34 new CollectionSpecification<Integer>(CollectionSpecification.CollectionSpecificationScope.SIZE,
35 new EqualSpecification<Integer>(10));
36
37 @Test
38 public void shouldNotAcceptNull() {
39 try {
40 collectionWithTenElements.isDisjointWith(null);
41 fail("Should have thrown exception");
42
43 } catch (IllegalArgumentException e) {
44 String expectedMessage = "Specification parameter cannot be null";
45 String actualMessage = e.getMessage();
46 assertEquals(expectedMessage, actualMessage);
47 }
48 }
49
50
51 @Test
52 public void shouldNotBeReflexive() {
53 assertFalse(collectionWithTenElements.isDisjointWith(collectionWithTenElements));
54 }
55
56
57 @Test
58 public void shouldHandleNegatedNullCollectionSpecification() {
59 Specification<?> spec = hasSize(equalTo(0));
60 assertFalse(spec.isDisjointWith(spec));
61
62 Specification<?> spec2 = not(spec);
63 assertFalse(spec2.isDisjointWith(spec2));
64 assertTrue(spec2.isDisjointWith(spec));
65 assertTrue(spec.isDisjointWith(spec2));
66
67 Specification<?> spec3 = is(not(spec));
68 assertFalse(spec3.isDisjointWith(spec3));
69 assertFalse(spec3.isDisjointWith(spec2));
70 assertFalse(spec2.isDisjointWith(spec3));
71 assertTrue(spec3.isDisjointWith(spec));
72 assertTrue(spec.isDisjointWith(spec3));
73 }
74 }