Added new constructor. May need to tighten down interfaces in the future.
[packetcable.git] / packetcable-driver / src / test / java / org / umu / cops / stack / COPSHandleFirstConstructorTest.java
1 package org.umu.cops.stack;
2
3 import org.junit.Assert;
4 import org.junit.Test;
5
6 /**
7  * Tests for the first constructor of the COPSHandle class.
8  * Should any of these tests be inaccurate it is due to the fact that they have been written after COPSHandle had been
9  * released and my assumptions may be incorrect.
10  */
11 public class COPSHandleFirstConstructorTest {
12
13     @Test (expected = IllegalArgumentException.class)
14     public void constructWithNullId() {
15         final COPSData id = null;
16         new COPSHandle(id);
17     }
18
19     @Test
20     public void constructWithDefaultId() {
21         final COPSData id = new COPSData();
22         final COPSHandle handle = new COPSHandle(id);
23         Assert.assertEquals(0, handle.getDataLength());
24         Assert.assertTrue(id.equals(handle.getId()));
25
26         final COPSHandle eqHash = new COPSHandle(id);
27         Assert.assertTrue(handle.equals(eqHash));
28         Assert.assertEquals(handle.hashCode(), eqHash.hashCode());
29     }
30
31     @Test
32     public void constructWithData() {
33         final COPSData id = new COPSData("12345");
34         final COPSHandle handle = new COPSHandle(id);
35
36         // TODO - need to determine if 12 is indeed correct given the value "123456778"
37         Assert.assertEquals(8, handle.getDataLength());
38         Assert.assertTrue(id.equals(handle.getId()));
39
40         final COPSHandle eqHash = new COPSHandle(id);
41         Assert.assertTrue(handle.equals(eqHash));
42         Assert.assertEquals(handle.hashCode(), eqHash.hashCode());
43     }
44
45 }