CosemDateConverter extends CustomConverter<byte[], CosemDate> { @Override public CosemDate convert(final byte[] source, final Type<? extends CosemDate> destinationType, final MappingContext context) { final ByteBuffer bb = ByteBuffer.wrap(source); final int year = bb.getShort() & 0xFFFF; final int month = bb.get() & 0xFF; final int day = bb.get() & 0xFF; final int weekDay = bb.get() & 0xFF; return new CosemDate(year, month, day, weekDay); }  @Override CosemDate convert(final byte[] source, final Type<? extends CosemDate> destinationType,
            final MappingContext context);  }
@Test public void testWildCards() { byte[] source = new byte[] { (byte) 0x07, (byte) 0xDF, 6, (byte) 0xFF, (byte) 0xFF }; final CosemDateConverter converter = new CosemDateConverter(); CosemDate date = converter.convert(source, converter.getBType(), null); assertThat(date.getYear()).isEqualTo(2015); assertThat(date.getMonth()).isEqualTo(6); assertThat(date.getDayOfMonth()).isEqualTo(0xFF); assertThat(date.getDayOfWeek()).isEqualTo(0xFF); source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, (byte) 0xFD, (byte) 0xFF }; date = converter.convert(source, converter.getBType(), null); assertThat(date.getYear()).isEqualTo(0xFFFF); assertThat(date.getMonth()).isEqualTo(0xFE); assertThat(date.getDayOfMonth()).isEqualTo(0xFD); assertThat(date.getDayOfWeek()).isEqualTo(0xFF); source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, 21, 3 }; date = converter.convert(source, converter.getBType(), null); assertThat(date.getYear()).isEqualTo(0xFFFF); assertThat(date.getMonth()).isEqualTo(0xFE); assertThat(date.getDayOfMonth()).isEqualTo(21); assertThat(date.getDayOfWeek()).isEqualTo(3); }
@Test public void testWildCards() { byte[] source = new byte[] { (byte) 0x07, (byte) 0xDF, 6, (byte) 0xFF, (byte) 0xFF }; final CosemDateConverter converter = new CosemDateConverter(); CosemDate date = converter.convert(source, converter.getBType(), null); Assert.assertEquals(2015, date.getYear()); Assert.assertEquals(6, date.getMonth()); Assert.assertEquals(0xFF, date.getDayOfMonth()); Assert.assertEquals(0xFF, date.getDayOfWeek()); source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, (byte) 0xFD, (byte) 0xFF }; date = converter.convert(source, converter.getBType(), null); Assert.assertEquals(0xFFFF, date.getYear()); Assert.assertEquals(0xFE, date.getMonth()); Assert.assertEquals(0xFD, date.getDayOfMonth()); Assert.assertEquals(0xFF, date.getDayOfWeek()); source = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFE, 21, 3 }; date = converter.convert(source, converter.getBType(), null); Assert.assertEquals(0xFFFF, date.getYear()); Assert.assertEquals(0xFE, date.getMonth()); Assert.assertEquals(21, date.getDayOfMonth()); Assert.assertEquals(3, date.getDayOfWeek()); }