BitmaskMeasurementElement implements MeasurementElement, Serializable { public Set<BitmaskFlag> asEnumSet() { final Set<BitmaskFlag> bitmaskFlags = EnumSet.noneOf(BitmaskFlag.class); for (final BitmaskFlag flag : BitmaskFlag.values()) { if ((this.value & flag.value) > 0) { bitmaskFlags.add(flag); } } return bitmaskFlags; } BitmaskMeasurementElement(final Byte value); Byte getValue(); boolean getFlag(final BitmaskFlag flag); Set<BitmaskFlag> asEnumSet(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void asEnumSetShouldReturnCorrectEnumSetForAllFlagsSet() { final Byte bitmask = (byte) 255; final BitmaskMeasurementElement element = new BitmaskMeasurementElement(bitmask); final EnumSet<BitmaskFlag> expected = EnumSet.allOf(BitmaskFlag.class); final Set<BitmaskFlag> actual = element.asEnumSet(); assertThat(actual).isEqualTo(expected); }
@Test public void asEnumSetShouldReturnCorrectEnumSetForFlag8Set() { final Byte bitmask = (byte) 128; final BitmaskMeasurementElement element = new BitmaskMeasurementElement(bitmask); final EnumSet<BitmaskFlag> expected = EnumSet.noneOf(BitmaskFlag.class); expected.add(BitmaskFlag.FLAG_8); final Set<BitmaskFlag> actual = element.asEnumSet(); assertThat(actual).isEqualTo(expected); }
@Test public void asEnumSetShouldReturnCorrectEnumSetWhenFlag1Set() { final Byte bitmask = 1; final BitmaskMeasurementElement element = new BitmaskMeasurementElement(bitmask); final EnumSet<BitmaskFlag> expected = EnumSet.noneOf(BitmaskFlag.class); expected.add(BitmaskFlag.FLAG_1); final Set<BitmaskFlag> actual = element.asEnumSet(); assertThat(actual).isEqualTo(expected); }
@Test public void asEnumSetShouldReturnCorrectEnumSetWhenNoFlagsSet() { final Byte bitmask = 0; final BitmaskMeasurementElement element = new BitmaskMeasurementElement(bitmask); final EnumSet<BitmaskFlag> expected = EnumSet.noneOf(BitmaskFlag.class); final Set<BitmaskFlag> actual = element.asEnumSet(); assertThat(actual).isEqualTo(expected); }