View Javadoc
1   /*
2    * Copyright 2008 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 org.openehealth.ipf.platform.camel.core.process.splitter;
17  
18  import static org.junit.Assert.*;
19  
20  import org.junit.Test;
21  import org.openehealth.ipf.platform.camel.core.process.splitter.SplitIndex;
22  import org.openehealth.ipf.platform.camel.core.process.splitter.Splitter;
23  
24  
25  /**
26   * @author Jens Riemschneider
27   */
28  public class SplitIndexTest {
29      @Test
30      public void testValueOf() {
31          SplitIndex index = SplitIndex.valueOf(14, true);
32          assertEquals(14, index.getIndex());
33          assertEquals(true, index.isLast());
34      }
35      
36      @Test
37      public void testEquals() {
38          SplitIndex index1a = SplitIndex.valueOf(4, false);
39          SplitIndex index1b = SplitIndex.valueOf(4, false);
40          SplitIndex index2 = SplitIndex.valueOf(5, false);
41          SplitIndex index3 = SplitIndex.valueOf(4, true);
42          
43          assertTrue("Should be equal", index1a.equals(index1b));
44          assertFalse("Should not be equal", index1a.equals(index2));
45          assertFalse("Should not be equal", index1a.equals(index3));
46          
47          assertFalse("Null is never equal", index1a.equals(null));
48          assertFalse("Unrelated class is never equal", index1a.equals(this));
49          
50          assertTrue("Same instances should be equal", index1a.equals(index1a));
51      }
52      
53      @Test
54      public void testHashCode() {
55          SplitIndex index1a = SplitIndex.valueOf(4, false);
56          SplitIndex index1b = SplitIndex.valueOf(4, false);
57          SplitIndex index2 = SplitIndex.valueOf(5, false);
58          SplitIndex index3 = SplitIndex.valueOf(4, true);
59          
60          assertEquals(index1a.hashCode(), index1b.hashCode());
61          
62          // Not necessary, but hash code shouldn't be too weak 
63          assertTrue(index1a.hashCode() != index2.hashCode());
64          assertTrue(index1a.hashCode() != index3.hashCode());
65      }
66      
67      @Test
68      public void testToString() {
69          SplitIndex index = SplitIndex.valueOf(14, true);
70          String str = index.toString();
71          assertTrue("Class name missing", str.contains(Splitter.class.getName()));
72          assertTrue("index missing", str.contains("14"));
73          assertTrue("last flag missing", str.contains("true"));
74      }
75  }