|
1 | | -/** |
2 | | - * Copyright information and license terms for this software can be |
3 | | - * found in the file LICENSE.TXT included with the distribution. |
4 | | - */ |
5 | | -package org.epics.vtype; |
6 | | - |
7 | | -import java.time.Instant; |
8 | | -import org.junit.Test; |
9 | | -import static org.junit.Assert.*; |
10 | | -import static org.hamcrest.Matchers.*; |
11 | | - |
12 | | -/** |
13 | | - * |
14 | | - * @author carcassi |
15 | | - */ |
16 | | -public class VEnumTest { |
17 | | - |
18 | | - @Test |
19 | | - public void of1() { |
20 | | - EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
21 | | - Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
22 | | - Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
23 | | - VEnum value = VEnum.of(0, display, alarm, time); |
24 | | - assertThat(value.getValue(), equalTo("A")); |
25 | | - assertThat(value.getIndex(), equalTo(0)); |
26 | | - assertThat(value.getAlarm(), equalTo(alarm)); |
27 | | - assertThat(value.getTime(), equalTo(time)); |
28 | | - assertThat(value.getDisplay(), equalTo(display)); |
29 | | - assertThat(value.toString(), equalTo("VEnum[\"A\", MINOR(DB) - LOW, 2012-12-05T14:57:21.521786982Z]")); |
30 | | - } |
31 | | - |
32 | | - @Test(expected = NullPointerException.class) |
33 | | - public void of2() { |
34 | | - VEnum value = VEnum.of(0, null, Alarm.none(), Time.now()); |
35 | | - } |
36 | | - |
37 | | - @Test(expected = NullPointerException.class) |
38 | | - public void of3() { |
39 | | - VEnum value = VEnum.of(0, EnumDisplay.of(3), null, Time.now()); |
40 | | - } |
41 | | - |
42 | | - @Test(expected = NullPointerException.class) |
43 | | - public void of4() { |
44 | | - VEnum value = VEnum.of(0, EnumDisplay.of(3), Alarm.none(), null); |
45 | | - } |
46 | | - |
47 | | - @Test(expected = IndexOutOfBoundsException.class) |
48 | | - public void of5() { |
49 | | - VEnum value = VEnum.of(-1, EnumDisplay.of(3), Alarm.none(), Time.now()); |
50 | | - } |
51 | | - |
52 | | - @Test(expected = IndexOutOfBoundsException.class) |
53 | | - public void of6() { |
54 | | - VEnum value = VEnum.of(3, EnumDisplay.of(3), Alarm.none(), Time.now()); |
55 | | - } |
56 | | - |
57 | | - @Test |
58 | | - public void equals1() { |
59 | | - EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
60 | | - Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
61 | | - Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
62 | | - Time now = Time.now(); |
63 | | - assertThat(VEnum.of(0, display, alarm, time), equalTo(VEnum.of(0, display, alarm, time))); |
64 | | - assertThat(VEnum.of(1, display, Alarm.none(), now), equalTo(VEnum.of(1, display, Alarm.none(), now))); |
65 | | - assertThat(VEnum.of(0, display, alarm, time), not(equalTo(null))); |
66 | | - assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(1, display, alarm, time)))); |
67 | | - assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, EnumDisplay.of(3), alarm, time)))); |
68 | | - assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, display, Alarm.none(), time)))); |
69 | | - assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, display, alarm, now)))); |
70 | | - } |
71 | | - |
72 | | - @Test |
73 | | - public void hashCode1() { |
74 | | - EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
75 | | - Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
76 | | - Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
77 | | - Time now = Time.now(); |
78 | | - assertThat(VEnum.of(0, display, alarm, time).hashCode(), equalTo(VEnum.of(0, display, alarm, time).hashCode())); |
79 | | - assertThat(VEnum.of(1, display, Alarm.none(), now).hashCode(), equalTo(VEnum.of(1, display, Alarm.none(), now).hashCode())); |
80 | | - assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(1, display, alarm, time).hashCode()))); |
81 | | - assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, EnumDisplay.of(3), alarm, time).hashCode()))); |
82 | | - assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, display, Alarm.none(), time).hashCode()))); |
83 | | - assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, display, alarm, now).hashCode()))); |
84 | | - } |
85 | | - |
86 | | -} |
| 1 | +/** |
| 2 | + * Copyright information and license terms for this software can be |
| 3 | + * found in the file LICENSE.TXT included with the distribution. |
| 4 | + */ |
| 5 | +package org.epics.vtype; |
| 6 | + |
| 7 | +import java.time.Instant; |
| 8 | +import org.junit.Test; |
| 9 | +import static org.junit.Assert.*; |
| 10 | +import static org.hamcrest.Matchers.*; |
| 11 | + |
| 12 | +/** |
| 13 | + * |
| 14 | + * @author carcassi |
| 15 | + */ |
| 16 | +public class VEnumTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void of1() { |
| 20 | + EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
| 21 | + Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
| 22 | + Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
| 23 | + VEnum value = VEnum.of(0, display, alarm, time); |
| 24 | + assertThat(value.getValue(), equalTo("A")); |
| 25 | + assertThat(value.getIndex(), equalTo(0)); |
| 26 | + assertThat(value.getAlarm(), equalTo(alarm)); |
| 27 | + assertThat(value.getTime(), equalTo(time)); |
| 28 | + assertThat(value.getDisplay(), equalTo(display)); |
| 29 | + assertThat(value.toString(), equalTo("VEnum[\"A\", MINOR(DB) - LOW, 2012-12-05T14:57:21.521786982Z]")); |
| 30 | + } |
| 31 | + |
| 32 | + @Test(expected = NullPointerException.class) |
| 33 | + public void of2() { |
| 34 | + VEnum value = VEnum.of(0, null, Alarm.none(), Time.now()); |
| 35 | + } |
| 36 | + |
| 37 | + @Test(expected = NullPointerException.class) |
| 38 | + public void of3() { |
| 39 | + VEnum value = VEnum.of(0, EnumDisplay.of(3), null, Time.now()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test(expected = NullPointerException.class) |
| 43 | + public void of4() { |
| 44 | + VEnum value = VEnum.of(0, EnumDisplay.of(3), Alarm.none(), null); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void equals1() { |
| 49 | + EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
| 50 | + Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
| 51 | + Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
| 52 | + Time now = Time.now(); |
| 53 | + assertThat(VEnum.of(0, display, alarm, time), equalTo(VEnum.of(0, display, alarm, time))); |
| 54 | + assertThat(VEnum.of(1, display, Alarm.none(), now), equalTo(VEnum.of(1, display, Alarm.none(), now))); |
| 55 | + assertThat(VEnum.of(0, display, alarm, time), not(equalTo(null))); |
| 56 | + assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(1, display, alarm, time)))); |
| 57 | + assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, EnumDisplay.of(3), alarm, time)))); |
| 58 | + assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, display, Alarm.none(), time)))); |
| 59 | + assertThat(VEnum.of(0, display, alarm, time), not(equalTo(VEnum.of(0, display, alarm, now)))); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void hashCode1() { |
| 64 | + EnumDisplay display = EnumDisplay.of("A", "B", "C"); |
| 65 | + Alarm alarm = Alarm.of(AlarmSeverity.MINOR, AlarmStatus.DB, "LOW"); |
| 66 | + Time time = Time.of(Instant.ofEpochSecond(1354719441, 521786982)); |
| 67 | + Time now = Time.now(); |
| 68 | + assertThat(VEnum.of(0, display, alarm, time).hashCode(), equalTo(VEnum.of(0, display, alarm, time).hashCode())); |
| 69 | + assertThat(VEnum.of(1, display, Alarm.none(), now).hashCode(), equalTo(VEnum.of(1, display, Alarm.none(), now).hashCode())); |
| 70 | + assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(1, display, alarm, time).hashCode()))); |
| 71 | + assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, EnumDisplay.of(3), alarm, time).hashCode()))); |
| 72 | + assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, display, Alarm.none(), time).hashCode()))); |
| 73 | + assertThat(VEnum.of(0, display, alarm, time).hashCode(), not(equalTo(VEnum.of(0, display, alarm, now).hashCode()))); |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments