Source:
<code>public void testMinimalDeserilization() throws Exception { long now = System.currentTimeMillis(); long nowWritePointer = now * TxConstants.MAX_TX_PER_MS; long tInvalid = nowWritePointer - 5; long readPtr = nowWritePointer - 4; long tLong = nowWritePointer - 3; long tCommitted = nowWritePointer - 2; long tShort = nowWritePointer - 1; TreeMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap(ImmutableSortedMap.of( tLong, new TransactionManager.InProgressTx(readPtr, TransactionManager.getTxExpirationFromWritePointer( tLong, TxConstants.Manager.DEFAULT_TX_LONG_TIMEOUT), TransactionType.LONG), tShort, new TransactionManager.InProgressTx(readPtr, now + 1000, TransactionType.SHORT))); TransactionSnapshot snapshot = new TransactionSnapshot(now, readPtr, nowWritePointer, Lists.newArrayList(tInvalid), inProgress, ImmutableMap.<Long, Set<ChangeId>>of( tShort, Sets.<ChangeId>newHashSet()), ImmutableMap.<Long, Set<ChangeId>>of( tCommitted, Sets.<ChangeId>newHashSet())); Configuration conf1 = new Configuration(); conf1.set(TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES, SnapshotCodecV4.class.getName()); SnapshotCodecProvider provider1 = new SnapshotCodecProvider(conf1); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { provider1.encode(out, snapshot); } finally { out.close(); } byte[] byteArray = out.toByteArray(); TransactionSnapshot txSnapshot = provider1.decode(new ByteArrayInputStream(byteArray)); TransactionVisibilityState txVisibilityState = provider1.decodeTransactionVisibilityState(new ByteArrayInputStream(byteArray)); assertTransactionVisibilityStateEquals(txSnapshot, txVisibilityState); byteArray[byteArray.length - 1] = 'a'; TransactionVisibilityState minSnapshot = provider1.decodeTransactionVisibilityState( new ByteArrayInputStream(byteArray)); Assert.assertEquals(readPtr, minSnapshot.getReadPointer()); <START> Assert.assertNotNull(minSnapshot); <END> try { provider1.decode(new ByteArrayInputStream(byteArray)); Assert.fail(); } catch (RuntimeException e) { } }</code><technical_language>is a good idea move this assertion minSnapshot</technical_language>

Target:
public void testMinimalDeserilization() throws Exception { long now = System.currentTimeMillis(); long nowWritePointer = now * TxConstants.MAX_TX_PER_MS; long tInvalid = nowWritePointer - 5; long readPtr = nowWritePointer - 4; long tLong = nowWritePointer - 3; long tCommitted = nowWritePointer - 2; long tShort = nowWritePointer - 1; TreeMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap(ImmutableSortedMap.of( tLong, new TransactionManager.InProgressTx(readPtr, TransactionManager.getTxExpirationFromWritePointer( tLong, TxConstants.Manager.DEFAULT_TX_LONG_TIMEOUT), TransactionType.LONG), tShort, new TransactionManager.InProgressTx(readPtr, now + 1000, TransactionType.SHORT))); TransactionSnapshot snapshot = new TransactionSnapshot(now, readPtr, nowWritePointer, Lists.newArrayList(tInvalid), inProgress, ImmutableMap.<Long, Set<ChangeId>>of( tShort, Sets.<ChangeId>newHashSet()), ImmutableMap.<Long, Set<ChangeId>>of( tCommitted, Sets.<ChangeId>newHashSet())); Configuration conf1 = new Configuration(); conf1.set(TxConstants.Persist.CFG_TX_SNAPHOT_CODEC_CLASSES, SnapshotCodecV4.class.getName()); SnapshotCodecProvider provider1 = new SnapshotCodecProvider(conf1); byte[] byteArray; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { provider1.encode(out, snapshot); byteArray = out.toByteArray(); } TransactionSnapshot txSnapshot = provider1.decode(new ByteArrayInputStream(byteArray)); TransactionVisibilityState txVisibilityState = provider1.decodeTransactionVisibilityState(new ByteArrayInputStream(byteArray)); assertTransactionVisibilityStateEquals(txSnapshot, txVisibilityState); byteArray[byteArray.length - 1] = 'a'; TransactionVisibilityState txVisibilityState2 = provider1.decodeTransactionVisibilityState( new ByteArrayInputStream(byteArray)); Assert.assertNotNull(txVisibilityState2); Assert.assertEquals(txVisibilityState, txVisibilityState2); Assert.assertEquals(readPtr, txVisibilityState2.getReadPointer()); try { provider1.decode(new ByteArrayInputStream(byteArray)); Assert.fail(); } catch (RuntimeException e) { } }