all: remove build_host and build_date to enable reproducible building
[olsrd.git] / lib / info.java / org.olsr.v1.info.api / test / org / olsr / v1 / info / api / dto / TestJsonInfoVersionEntry.java
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 org.junit.After;
8 import org.junit.Before;
9 import org.junit.Test;
10
11 public class TestJsonInfoVersionEntry {
12   private JsonInfoVersionEntry impl = null;
13
14   @Before
15   public void setUp() {
16     this.impl = new JsonInfoVersionEntry();
17   }
18
19   @After
20   public void tearDown() {
21     this.impl = null;
22   }
23
24   @Test(timeout = 8000)
25   public void testGettersAndSetters() {
26     /* initial */
27     assertThat(this.impl.getVersion(), equalTo(""));
28     assertThat(this.impl.getBuildDate(), equalTo(""));
29     assertThat(this.impl.getBuildHost(), equalTo(""));
30     assertThat(this.impl.getGitDescriptor(), equalTo(""));
31     assertThat(this.impl.getGitSha(), equalTo(""));
32     assertThat(this.impl.getReleaseVersion(), equalTo(""));
33     assertThat(this.impl.getSourceHash(), equalTo(""));
34
35     /* set */
36     this.impl.setVersion("version");
37     this.impl.setBuildDate("date");
38     this.impl.setBuildHost("host");
39     this.impl.setGitDescriptor("gitDescriptor");
40     this.impl.setGitSha("gitSha");
41     this.impl.setReleaseVersion("releaseVersion");
42     this.impl.setSourceHash("sourceHash");
43
44     /* get */
45     assertThat(this.impl.getVersion(), equalTo("version"));
46     assertThat(this.impl.getBuildDate(), equalTo("date"));
47     assertThat(this.impl.getBuildHost(), equalTo("host"));
48     assertThat(this.impl.getGitDescriptor(), equalTo("gitDescriptor"));
49     assertThat(this.impl.getGitSha(), equalTo("gitSha"));
50     assertThat(this.impl.getReleaseVersion(), equalTo("releaseVersion"));
51     assertThat(this.impl.getSourceHash(), equalTo("sourceHash"));
52   }
53
54   @Test(timeout = 8000)
55   public void testCompareTo() {
56     int r;
57     final JsonInfoVersionEntry other = new JsonInfoVersionEntry();
58
59     final String version1 = "version1";
60     final String version2 = "version2";
61     final String date1 = "date1";
62     final String date2 = "date2";
63     final String host1 = "host1";
64     final String host2 = "host2";
65
66     /* null */
67
68     r = this.impl.compareTo(null);
69     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
70
71     /* version */
72
73     final String versionOrg = this.impl.getVersion();
74
75     this.impl.setVersion(null);
76     other.setVersion(version2);
77     r = this.impl.compareTo(other);
78     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
79
80     this.impl.setVersion(version2);
81     other.setVersion(null);
82     r = this.impl.compareTo(other);
83     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
84
85     this.impl.setVersion(version1);
86     other.setVersion(version2);
87     r = this.impl.compareTo(other);
88     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
89
90     this.impl.setVersion(version1);
91     other.setVersion(version1);
92     r = this.impl.compareTo(other);
93     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
94
95     this.impl.setVersion(versionOrg);
96     other.setVersion(versionOrg);
97
98     /* date */
99
100     final String dateOrg = this.impl.getBuildDate();
101
102     this.impl.setBuildDate(null);
103     other.setBuildDate(date2);
104     r = this.impl.compareTo(other);
105     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
106
107     this.impl.setBuildDate(date2);
108     other.setBuildDate(null);
109     r = this.impl.compareTo(other);
110     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
111
112     this.impl.setBuildDate(date1);
113     other.setBuildDate(date2);
114     r = this.impl.compareTo(other);
115     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
116
117     this.impl.setBuildDate(date1);
118     other.setBuildDate(date1);
119     r = this.impl.compareTo(other);
120     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
121
122     this.impl.setBuildDate(dateOrg);
123     other.setBuildDate(dateOrg);
124
125     /* host */
126
127     final String hostOrg = this.impl.getBuildHost();
128
129     this.impl.setBuildHost(null);
130     other.setBuildHost(host2);
131     r = this.impl.compareTo(other);
132     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
133
134     this.impl.setBuildHost(host2);
135     other.setBuildHost(null);
136     r = this.impl.compareTo(other);
137     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
138
139     this.impl.setBuildHost(host1);
140     other.setBuildHost(host2);
141     r = this.impl.compareTo(other);
142     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
143
144     this.impl.setBuildHost(host1);
145     other.setBuildHost(host1);
146     r = this.impl.compareTo(other);
147     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
148
149     this.impl.setBuildHost(hostOrg);
150     other.setBuildHost(hostOrg);
151
152     /* gitDescriptor */
153
154     final String gitDescriptorOrg = this.impl.getGitDescriptor();
155
156     this.impl.setGitDescriptor(null);
157     other.setGitDescriptor(host2);
158     r = this.impl.compareTo(other);
159     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
160
161     this.impl.setGitDescriptor(host2);
162     other.setGitDescriptor(null);
163     r = this.impl.compareTo(other);
164     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
165
166     this.impl.setGitDescriptor(host1);
167     other.setGitDescriptor(host2);
168     r = this.impl.compareTo(other);
169     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
170
171     this.impl.setGitDescriptor(host1);
172     other.setGitDescriptor(host1);
173     r = this.impl.compareTo(other);
174     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
175
176     this.impl.setGitDescriptor(gitDescriptorOrg);
177     other.setGitDescriptor(gitDescriptorOrg);
178
179     /* gitSha */
180
181     final String gitShaOrg = this.impl.getGitSha();
182
183     this.impl.setGitSha(null);
184     other.setGitSha(host2);
185     r = this.impl.compareTo(other);
186     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
187
188     this.impl.setGitSha(host2);
189     other.setGitSha(null);
190     r = this.impl.compareTo(other);
191     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
192
193     this.impl.setGitSha(host1);
194     other.setGitSha(host2);
195     r = this.impl.compareTo(other);
196     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
197
198     this.impl.setGitSha(host1);
199     other.setGitSha(host1);
200     r = this.impl.compareTo(other);
201     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
202
203     this.impl.setGitSha(gitShaOrg);
204     other.setGitSha(gitShaOrg);
205
206     /* releaseVersion */
207
208     final String releaseVersionOrg = this.impl.getReleaseVersion();
209
210     this.impl.setReleaseVersion(null);
211     other.setReleaseVersion(host2);
212     r = this.impl.compareTo(other);
213     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
214
215     this.impl.setReleaseVersion(host2);
216     other.setReleaseVersion(null);
217     r = this.impl.compareTo(other);
218     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
219
220     this.impl.setReleaseVersion(host1);
221     other.setReleaseVersion(host2);
222     r = this.impl.compareTo(other);
223     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
224
225     this.impl.setReleaseVersion(host1);
226     other.setReleaseVersion(host1);
227     r = this.impl.compareTo(other);
228     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
229
230     this.impl.setReleaseVersion(releaseVersionOrg);
231     other.setReleaseVersion(releaseVersionOrg);
232
233     /* sourceHash */
234
235     final String sourceHashOrg = this.impl.getSourceHash();
236
237     this.impl.setSourceHash(null);
238     other.setSourceHash(host2);
239     r = this.impl.compareTo(other);
240     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
241
242     this.impl.setSourceHash(host2);
243     other.setSourceHash(null);
244     r = this.impl.compareTo(other);
245     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1)));
246
247     this.impl.setSourceHash(host1);
248     other.setSourceHash(host2);
249     r = this.impl.compareTo(other);
250     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(-1)));
251
252     this.impl.setSourceHash(host1);
253     other.setSourceHash(host1);
254     r = this.impl.compareTo(other);
255     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(0)));
256
257     this.impl.setSourceHash(sourceHashOrg);
258     other.setSourceHash(sourceHashOrg);
259   }
260
261   @Test(timeout = 8000)
262   public void testEquals() {
263     boolean r;
264     JsonInfoVersionEntry other;
265
266     r = this.impl.equals(this.impl);
267     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
268
269     other = null;
270     r = this.impl.equals(other);
271     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
272
273     final Object otherObj = new Object();
274     r = this.impl.equals(otherObj);
275     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
276
277     other = new JsonInfoVersionEntry();
278     r = this.impl.equals(other);
279     assertThat(Boolean.valueOf(r), equalTo(Boolean.TRUE));
280
281     other.setVersion("version");
282     r = this.impl.equals(other);
283     assertThat(Boolean.valueOf(r), equalTo(Boolean.FALSE));
284   }
285
286   @Test(timeout = 8000)
287   public void testHashCode() {
288     int r = this.impl.hashCode();
289     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(1742810335)));
290
291     this.impl.setVersion("version");
292     this.impl.setBuildDate("date");
293     this.impl.setBuildHost("host");
294     this.impl.setGitDescriptor("gitDescriptor");
295     this.impl.setGitSha("gitSha");
296     this.impl.setReleaseVersion("releaseVersion");
297     this.impl.setSourceHash("sourceHash");
298
299     r = this.impl.hashCode();
300     assertThat(Integer.valueOf(r), equalTo(Integer.valueOf(632880642)));
301   }
302
303   @Test(timeout = 8000)
304   public void testToString() {
305     final String r = this.impl.toString();
306     assertThat(r, notNullValue());
307   }
308 }