1   /*
2    * Copyright 2006-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }