1 package org.olsr.v1.info.api.dto;
2 
3 import static org.hamcrest.core.IsEqual.equalTo;
4 import static org.hamcrest.core.IsNull.notNullValue;
5 import static org.junit.Assert.assertThat;
6 
7 import java.io.File;
8 import java.io.IOException;
9 import java.util.LinkedList;
10 import java.util.List;
11 
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 
16 @SuppressWarnings("static-method")
17 public class TestJsonInfoInterfaces {
18   private JsonInfoInterfaces impl = null;
19 
20   @Before
setUp()21   public void setUp() {
22     this.impl = new JsonInfoInterfaces();
23   }
24 
25   @After
tearDown()26   public void tearDown() {
27     this.impl = null;
28   }
29 
30   @Test(timeout = 8000)
testGettersAndSetters()31   public void testGettersAndSetters() {
32     /* initial */
33     assertThat(this.impl.getInterfaces(), notNullValue());
34     assertThat(Boolean.valueOf(this.impl.getInterfaces().isEmpty()), equalTo(Boolean.TRUE));
35 
36     /* set */
37     final List<JsonInfoInterfacesEntry> mid = new LinkedList<>();
38     final JsonInfoInterfacesEntry entry = new JsonInfoInterfacesEntry();
39     entry.setName("name");
40     mid.add(entry);
41     this.impl.setInterfaces(mid);
42 
43     /* get */
44     assertThat(this.impl.getInterfaces(), equalTo(mid));
45   }
46 
47   @Test(timeout = 8000)
testEquals()48   public void testEquals() {
49     boolean r;
50     final Object otherNull = null;
51     final JsonInfoInterfaces otherSuperNotEqual = new JsonInfoInterfaces();
52     otherSuperNotEqual.setTimeSinceStartup(321);
53     final JsonInfoInterfaces other = new JsonInfoInterfaces();
54     final JsonInfoInterfacesEntry e = new JsonInfoInterfacesEntry();
55     final JsonInfoInterfacesEntry e1 = new JsonInfoInterfacesEntry();
56     final List<JsonInfoInterfacesEntry> nei1 = new LinkedList<>();
57     nei1.add(e);
58     final List<JsonInfoInterfacesEntry> nei2 = new LinkedList<>();
59     nei2.add(e1);
60 
61     r = this.impl.equals(this.impl);
62     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
63 
64     r = this.impl.equals(otherNull);
65     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
66 
67     r = this.impl.equals(otherSuperNotEqual);
68     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
69 
70     this.impl.setInterfaces(null);
71     other.setInterfaces(null);
72     r = this.impl.equals(other);
73     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
74 
75     this.impl.setInterfaces(nei1);
76     other.setInterfaces(null);
77     r = this.impl.equals(other);
78     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
79 
80     this.impl.setInterfaces(null);
81     other.setInterfaces(nei2);
82     r = this.impl.equals(other);
83     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
84 
85     this.impl.setInterfaces(nei1);
86     other.setInterfaces(nei2);
87     r = this.impl.equals(other);
88     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
89 
90     final JsonInfoInterfacesEntry entry = new JsonInfoInterfacesEntry();
91     nei2.add(entry);
92 
93     this.impl.setInterfaces(nei1);
94     other.setInterfaces(nei2);
95     r = this.impl.equals(other);
96     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
97   }
98 
99   @Test(timeout = 8000)
testHashCode()100   public void testHashCode() {
101     this.impl.setInterfaces(null);
102     int r = this.impl.hashCode();
103     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1742810336)));
104 
105     final List<JsonInfoInterfacesEntry> mid = new LinkedList<>();
106     final JsonInfoInterfacesEntry entry = new JsonInfoInterfacesEntry();
107     entry.setName("name");
108     mid.add(entry);
109     this.impl.setInterfaces(mid);
110 
111     r = this.impl.hashCode();
112     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(380319762)));
113   }
114 
115   @Test(timeout = 8000)
testToString()116   public void testToString() {
117     final String r = this.impl.toString();
118     assertThat(r, notNullValue());
119   }
120 
121   @Test(timeout = 8000)
testJSON()122   public void testJSON() throws IOException {
123     final String fn = "doc/examples/interfaces.json";
124 
125     final String output = Helpers.readFile(new File(fn));
126     final JsonInfoInterfaces gws = Helpers.objectMapper.readValue(output, JsonInfoInterfaces.class);
127     assertThat(gws, notNullValue());
128   }
129 }