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.Set; 10 import java.util.TreeSet; 11 12 import org.junit.After; 13 import org.junit.Before; 14 import org.junit.Test; 15 16 @SuppressWarnings("static-method") 17 public class TestJsonInfoNeighbors { 18 private JsonInfoNeighbors impl = null; 19 20 @Before setUp()21 public void setUp() { 22 this.impl = new JsonInfoNeighbors(); 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.getNeighbors(), notNullValue()); 34 assertThat(Boolean.valueOf(this.impl.getNeighbors().isEmpty()), equalTo(Boolean.TRUE)); 35 36 /* set */ 37 final Set<JsonInfoNeighborsEntry> neighbors = new TreeSet<>(); 38 final JsonInfoNeighborsEntry entry = new JsonInfoNeighborsEntry(); 39 entry.setLinkcount(1); 40 neighbors.add(entry); 41 this.impl.setNeighbors(neighbors); 42 43 /* get */ 44 assertThat(this.impl.getNeighbors(), equalTo(neighbors)); 45 } 46 47 @Test(timeout = 8000) testEquals()48 public void testEquals() { 49 boolean r; 50 final Object otherNull = null; 51 final JsonInfoNeighbors otherSuperNotEqual = new JsonInfoNeighbors(); 52 otherSuperNotEqual.setTimeSinceStartup(321); 53 final JsonInfoNeighbors other = new JsonInfoNeighbors(); 54 final JsonInfoNeighborsEntry e = new JsonInfoNeighborsEntry(); 55 final JsonInfoNeighborsEntry e1 = new JsonInfoNeighborsEntry(); 56 final Set<JsonInfoNeighborsEntry> nei1 = new TreeSet<>(); 57 nei1.add(e); 58 final Set<JsonInfoNeighborsEntry> nei2 = new TreeSet<>(); 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.setNeighbors(null); 71 other.setNeighbors(null); 72 r = this.impl.equals(other); 73 assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE)); 74 75 this.impl.setNeighbors(nei1); 76 other.setNeighbors(null); 77 r = this.impl.equals(other); 78 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 79 80 this.impl.setNeighbors(null); 81 other.setNeighbors(nei2); 82 r = this.impl.equals(other); 83 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 84 85 this.impl.setNeighbors(nei1); 86 other.setNeighbors(nei2); 87 r = this.impl.equals(other); 88 assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE)); 89 90 JsonInfoNeighborsEntry entry = new JsonInfoNeighborsEntry(); 91 nei2.add(entry); 92 93 this.impl.setNeighbors(nei1); 94 other.setNeighbors(nei2); 95 r = this.impl.equals(other); 96 assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE)); 97 98 entry = new JsonInfoNeighborsEntry(); 99 entry.setIsMultiPointRelay(true); 100 nei2.add(entry); 101 102 this.impl.setNeighbors(nei1); 103 other.setNeighbors(nei2); 104 r = this.impl.equals(other); 105 assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE)); 106 } 107 108 @Test(timeout = 8000) testHashCode()109 public void testHashCode() { 110 this.impl.setNeighbors(null); 111 int r = this.impl.hashCode(); 112 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1742810335))); 113 114 final Set<JsonInfoNeighborsEntry> neighbors = new TreeSet<>(); 115 final JsonInfoNeighborsEntry entry = new JsonInfoNeighborsEntry(); 116 entry.setLinkcount(1); 117 neighbors.add(entry); 118 this.impl.setNeighbors(neighbors); 119 120 r = this.impl.hashCode(); 121 assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(624033141))); 122 } 123 124 @Test(timeout = 8000) testToString()125 public void testToString() { 126 final String r = this.impl.toString(); 127 assertThat(r, notNullValue()); 128 } 129 130 @Test(timeout = 8000) testJSON()131 public void testJSON() throws IOException { 132 final String fn = "doc/examples/neighbors.json"; 133 134 final String output = Helpers.readFile(new File(fn)); 135 final JsonInfoNeighbors gws = Helpers.objectMapper.readValue(output, JsonInfoNeighbors.class); 136 assertThat(gws, notNullValue()); 137 } 138 }