MySQLDateBinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { int date = payload.getByteBuf().readUnsignedMediumLE(); return 0 == date ? MySQLTimeValueUtil.ZERO_OF_DATE : String.format("%d-%02d-%02d", date / 16 / 32, date / 32 % 16, date % 32); }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@Test public void assertRead() { when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedMediumLE()).thenReturn(1901 * 16 * 32 + 32 + 1); assertThat(new MySQLDateBinlogProtocolValue().read(columnDef, payload), is("1901-01-01")); }
@Test public void assertReadNullDate() { when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedMediumLE()).thenReturn(0); assertThat(new MySQLDateBinlogProtocolValue().read(columnDef, payload), is(MySQLTimeValueUtil.ZERO_OF_DATE)); }