|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-14 diirt developers. See COPYRIGHT.TXT |
| 3 | + * All rights reserved. Use is subject to license terms. See LICENSE.TXT |
| 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