target stringlengths 20 113k | src_fm stringlengths 11 86.3k | src_fm_fc stringlengths 21 86.4k | src_fm_fc_co stringlengths 30 86.4k | src_fm_fc_ms stringlengths 42 86.8k | src_fm_fc_ms_ff stringlengths 43 86.8k |
|---|---|---|---|---|---|
@Test void checkIdInGroupNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkIdInGroup(null)); } | @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } |
@Test void checkIdInGroupEmpty() { byte[] emptyId = new byte[0]; assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkIdInGroup(emptyId)); } | @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkIdInGroup(byte[] indexId) { checkArgument(indexId.length > 0, "index identifier must not be empty"); return indexId; } private StoragePreconditions(); } |
@Test void afterTransactions(TestKit testKit) { checkCounter(testKit, AFTER_TXS_COUNTER_NAME, 1L); for (int i = 1; i <= 2; i++) { testKit.createBlock(); checkCounter(testKit, AFTER_TXS_COUNTER_NAME, 1L + i); } } | @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration)... | QaServiceImpl extends AbstractService implements QaService { @Override public void afterTransactions(ExecutionContext context) { incrementCounter(AFTER_TXS_COUNTER_NAME, context); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext context, Configuration configuration)... |
@Test void checkStorageKeyAcceptsEmpty() { byte[] key = new byte[]{}; assertThat(key, sameInstance(StoragePreconditions.checkStorageKey(key))); } | @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } |
@Test void checkStorageKeyAcceptsNonEmpty() { byte[] key = bytes('k'); assertThat(key, sameInstance(StoragePreconditions.checkStorageKey(key))); } | @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } |
@Test void checkStorageKeyDoesNotAcceptNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkStorageKey(null)); } | @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } |
@Test void checkProofKeyAccepts32ByteZeroKey() { byte[] key = new byte[32]; assertThat(key, sameInstance(StoragePreconditions.checkProofKey(key))); } | @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } |
@Test void checkProofKeyAccepts32ByteNonZeroKey() { byte[] key = bytes("0123456789abcdef0123456789abcdef"); assertThat(key, sameInstance(StoragePreconditions.checkProofKey(key))); } | @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } |
@Test void checkProofKeyDoesNotAcceptNull() { NullPointerException thrown = assertThrows(NullPointerException.class, () -> StoragePreconditions.checkProofKey(null)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key is null")); } | @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } |
@Test void checkProofKeyDoesNotAcceptSmallerKeys() { byte[] key = new byte[1]; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkProofKey(key)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key has invalid size (1)")); } | @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } |
@Test void checkProofKeyDoesNotAcceptBiggerKeys() { byte[] key = new byte[64]; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkProofKey(key)); assertThat(thrown.getLocalizedMessage(), containsString("Proof map key has invalid size (64)")); } | @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkProofKey(byte[] key) { checkNotNull(key, "Proof map key is null"); checkArgument(key.length == PROOF_MAP_KEY_SIZE, "Proof map key has invalid size (%s), must be 32 bytes", key.length); return key; } private StoragePreconditions(); } |
@Test void checkStorageValueAcceptsEmpty() { byte[] value = new byte[]{}; assertThat(value, sameInstance(StoragePreconditions.checkStorageValue(value))); } | @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } |
@Test void checkStorageValueAcceptsNonEmpty() { byte[] value = bytes('v'); assertThat(value, sameInstance(StoragePreconditions.checkStorageValue(value))); } | @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageValue(byte[] value) { return checkNotNull(value, "Storage value is null"); } private StoragePreconditions(); } |
@Test void afterCommit(TestKit testKit) { testKit.createBlock(); checkAfterCommitCounter(testKit, 1L); testKit.createBlock(); checkAfterCommitCounter(testKit, 2L); } | @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); } | QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext conte... | QaServiceImpl extends AbstractService implements QaService { @Override public void afterCommit(BlockCommittedEvent event) { long seed = event.getHeight(); submitIncrementCounter(seed, AFTER_COMMIT_COUNTER_NAME); } @Inject QaServiceImpl(ServiceInstanceSpec instanceSpec); @Override void initialize(ExecutionContext conte... |
@Test void parseGetTxResponseInPool() { String json = "{\n" + " 'type': 'in-pool',\n" + " 'message': '" + toHex(TRANSACTION_MESSAGE) + "'\n" + "}"; TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); assertThat(transactionResponse.getStatus(), is(TransactionStatus.IN_POOL)); assertThat... | static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, response.getLocation() )... | ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, resp... | ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, resp... | ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, resp... | ExplorerApiHelper { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), response.getMessage(), executionResult, resp... |
@Test void checkStorageValueDoesNotAcceptNull() { assertThrows(NullPointerException.class, () -> StoragePreconditions.checkStorageKey(null)); } | @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static byte[] checkStorageKey(byte[] key) { return checkNotNull(key, "Storage key is null"); } private StoragePreconditions(); } |
@Test void checkNoNulls() { assertThrows(NullPointerException.class, () -> { Collection<String> c = Arrays.asList("hello", null); StoragePreconditions.checkNoNulls(c); }); } | static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } | StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } } | StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); } | StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); } | StoragePreconditions { static <E> void checkNoNulls(Collection<E> collection) { checkNotNull(collection, "Collection is null"); if (collection.contains(null)) { throw new NullPointerException("Collection contains nulls"); } } private StoragePreconditions(); } |
@Test void checkElementIndexNegative() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(-1, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: -1")); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndexEqualToSize() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(2, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: 2")); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndexGreaterThanSize() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(3, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but: 3")); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndexMaxLong() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkElementIndex(Long.MAX_VALUE, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Index must be in range [0, 2), but:")); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndex0MinValid() { long index = 0; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndex1() { long index = 1; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkElementIndex2MaxValid() { long index = 2; long size = 3; assertThat(StoragePreconditions.checkElementIndex(index, size), equalTo(index)); } | @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkElementIndex(long index, long size) { if (index < 0L || size <= index) { throw new IndexOutOfBoundsException("Index must be in range [0, " + size + ")," + " but: " + index); } return index; } private StoragePreconditions(); } |
@Test void checkPositionIndexSize0_Valid() { long index = 0; long size = 0; assertThat(StoragePreconditions.checkPositionIndex(index, size), equalTo(index)); } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void hasLength() { byte[] bytes = new byte[10]; assertTrue(CryptoUtils.hasLength(bytes, 10)); } | static boolean hasLength(byte[] data, int size) { return data.length == size; } | CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } } | CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); } | CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); } | CryptoUtils { static boolean hasLength(byte[] data, int size) { return data.length == size; } private CryptoUtils(); } |
@Test void checkPositionIndexSize0_NotValid() { long index = 1; long size = 0; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (1) is greater than size (0)")); } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void checkPositionIndexSize0_NotValidNegative() { long index = -1; long size = 0; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (-1) is negative")); } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void checkPositionIndexSize3_AllValid() { long size = 3; long[] validIndices = {0, 1, 2, 3}; for (long index : validIndices) { assertThat(StoragePreconditions.checkPositionIndex(index, size), equalTo(index)); } } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void checkPositionIndexSize3_NotValid() { long index = 4; long size = 3; IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("index (4) is greater than size (3)")); } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void checkPositionIndex_NegativeSize() { long index = 0; long size = -1; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> StoragePreconditions.checkPositionIndex(index, size)); assertThat(thrown.getLocalizedMessage(), containsString("size (-1) is negative")); } | @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } | StoragePreconditions { @CanIgnoreReturnValue static long checkPositionIndex(long index, long size) { if (index < 0 || index > size) { throw new IndexOutOfBoundsException(badPositionIndex(index, size)); } return index; } private StoragePreconditions(); } |
@Test void checkRangeFromNegative() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(-1, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index -1 must be in range [0, 2)")); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void checkRangeFromEqualToTo() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(2, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index 2 must be in range [0, 2)")); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void checkRangeFromGreaterThanTo() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(3, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index 3 must be in range [0, 2)")); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void checkRangeFromMaxLong() { IndexOutOfBoundsException thrown = assertThrows(IndexOutOfBoundsException.class, () -> checkRange(Long.MAX_VALUE, 2)); assertThat(thrown.getLocalizedMessage(), containsString("Proof range first element index " + Long.MAX_VALUE + " must be in range [0, 2)")); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void checkRangeFrom0MinValid() { long from = 0; long to = 3; checkRange(from, to); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void hexToByteArray() { byte[] bytes = CryptoUtils.hexToByteArray("abcd"); assertEquals(2, bytes.length); assertEquals(-85, bytes[0]); assertEquals(-51, bytes[1]); } | static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } | CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } } | CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); } | CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); } | CryptoUtils { static byte[] hexToByteArray(String hex) { return HEX_ENCODING.decode(hex); } private CryptoUtils(); } |
@Test void checkRangeFrom1() { long from = 1; long to = 3; checkRange(from, to); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void checkRangeFrom2MaxValid() { long from = 2; long to = 3; checkRange(from, to); } | static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } | StoragePreconditions { static void checkRange(long from, long to) { if (from < 0 || from >= to) { throw new IndexOutOfBoundsException("Proof range first element index " + from + " must be in range [0, " + to + ")"); } } private StoragePreconditions(); } |
@Test void trySplit_Empty() { int[] source = new int[0]; Spliterator<Integer> spliterator = createSpliteratorOf(source); assertNull(spliterator.trySplit()); } | @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValu... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... |
@Test @DisplayName("trySplit if there are less than minimal splittable size (1 element)") void trySplit_OneElement() { Spliterator<Integer> spliterator = createSpliteratorOf(new int[1]); assertNull(spliterator.trySplit()); } | @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValu... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... |
@Test void spliteratorRemainsBoundToTheSourceAfterSplit() { ListIndex<Integer> list = createListMock(); when(list.size()).thenReturn(10L); ModificationCounter counter = new IncrementalModificationCounter(); Spliterator<Integer> spliterator = new ListSpliterator<>(list, counter, true); Spliterator<Integer> other = split... | @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteristics(IMMUTABLE), nextIndex, mid, initialCounterValu... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... | ListSpliterator implements Spliterator<ElementT> { @Override public Spliterator<ElementT> trySplit() { bindOrCheckModifications(); if (estimateSize() < MIN_SPLITTABLE_SIZE) { return null; } long mid = nextIndex + (fence - nextIndex) / 2; Spliterator<ElementT> prefix = new ListSpliterator<>(list, counter, hasCharacteris... |
@Test @DisplayName("spliterator uses the list size at bind time, allowing for structural modifications") void spliteratorIsLateBindingUsesProperSize() { ListIndex<Integer> list = createListMock(); long initialSize = 10; lenient().when(list.size()).thenReturn(initialSize); ModificationCounter counter = new IncrementalMo... | @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } } | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... |
@Test void estimateSizeIsZeroAfterSpliteratorIsConsumed() { ListIndex<Integer> list = createListMock(); long listSize = 5; when(list.size()).thenReturn(listSize); ModificationCounter counter = mock(ModificationCounter.class); Spliterator<Integer> spliterator = new ListSpliterator<>(list, counter, true); spliterator.for... | @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } } | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... | ListSpliterator implements Spliterator<ElementT> { @Override public long estimateSize() { bindOrCheckModifications(); return fence - nextIndex; } ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boolean immutable); private ListSpliterator(ListIndex<ElementT> list, ModificationCounter counter, boo... |
@Test void isEmpty() { Block emptyBlock = Blocks.aBlock() .numTransactions(0) .build(); assertTrue(emptyBlock.isEmpty()); } | public final boolean isEmpty() { return getNumTransactions() == 0; } | Block { public final boolean isEmpty() { return getNumTransactions() == 0; } } | Block { public final boolean isEmpty() { return getNumTransactions() == 0; } } | Block { public final boolean isEmpty() { return getNumTransactions() == 0; } abstract HashCode getBlockHash(); abstract int getProposerId(); abstract long getHeight(); final boolean isEmpty(); abstract int getNumTransactions(); abstract HashCode getPreviousBlockHash(); abstract HashCode getTxRootHash(); abstract HashC... | Block { public final boolean isEmpty() { return getNumTransactions() == 0; } abstract HashCode getBlockHash(); abstract int getProposerId(); abstract long getHeight(); final boolean isEmpty(); abstract int getNumTransactions(); abstract HashCode getPreviousBlockHash(); abstract HashCode getTxRootHash(); abstract HashC... |
@Test void getWallet(VertxTestContext context) { long balance = 200L; Wallet wallet = new Wallet(balance); when(service.getWallet(eq(FROM_KEY))) .thenReturn(Optional.of(wallet)); String getWalletUri = getWalletUri(FROM_KEY); get(getWalletUri) .send(context.succeeding(response -> context.verify(() -> { assertThat(respon... | private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); }... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... |
@Test void getNonexistentWallet(VertxTestContext context) { when(service.getWallet(FROM_KEY)) .thenReturn(Optional.empty()); String getWalletUri = getWalletUri(FROM_KEY); get(getWalletUri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()).isEqualTo(HTTP_NOT_FOUND); context.co... | private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wallet.get())); }... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... | ApiController { private void getWallet(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); Optional<Wallet> wallet = service.getWallet(walletId); if (wallet.isPresent()) { rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(w... |
@Test void byteArrayToHex() { String hex = CryptoUtils.byteArrayToHex(new byte[]{-85, -51}); assertEquals("abcd", hex); } | static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } | CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } } | CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); } | CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); } | CryptoUtils { static String byteArrayToHex(byte[] bytes) { return HEX_ENCODING.encode(bytes); } private CryptoUtils(); } |
@Test void getWalletHistory(VertxTestContext context) { List<HistoryEntity> history = singletonList( HistoryEntity.newBuilder() .setSeed(1L) .setWalletFrom(FROM_KEY) .setWalletTo(TO_KEY) .setAmount(10L) .setTxMessageHash(HashCode.fromString("a0a0a0")) .build() ); when(service.getWalletHistory(FROM_KEY)).thenReturn(hist... | private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... |
@Test void getWalletHistoryNonexistentWallet(VertxTestContext context) { when(service.getWalletHistory(FROM_KEY)).thenReturn(emptyList()); String uri = getWalletUri(FROM_KEY) + "/history"; get(uri) .send(context.succeeding(response -> context.verify(() -> { assertThat(response.statusCode()).isEqualTo(HTTP_OK); assertTh... | private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(walletHistory)); } | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... | ApiController { private void getWalletHistory(RoutingContext rc) { PublicKey walletId = getRequiredParameter(rc.request(), WALLET_ID_PARAM, PublicKey::fromHexString); List<HistoryEntity> walletHistory = service.getWalletHistory(walletId); rc.response() .putHeader(CONTENT_TYPE, "application/json") .end(json().toJson(wal... |
@Test void parseFromWrongMessage() { byte[] message = bytes("Not a signed message"); assertThrows(InvalidProtocolBufferException.class, () -> SignedMessage.parseFrom(message)); } | public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } } | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... |
@Test void parseFromPayloadNotExonumMessage() { ByteString invalidPayload = ByteString.copyFrom( bytes("Invalid payload: not an ExonumMessage")); Types.PublicKey authorPk = aPublicKey().build(); Types.Signature signature = aSignature().build(); byte[] message = Messages.SignedMessage.newBuilder() .setPayload(invalidPay... | public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } } | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... | SignedMessage { public static SignedMessage parseFrom(byte[] messageBytes) throws InvalidProtocolBufferException { HashCode hash = sha256().hashBytes(messageBytes); Messages.SignedMessage message = Messages.SignedMessage.parseFrom(messageBytes); return fromProto(message, hash); } private SignedMessage(CoreMessage payl... |
@Test void testEquals() throws InvalidProtocolBufferException { String red = "Red"; String black = "Black"; EqualsVerifier.forClass(ParsedTransactionMessage.class) .suppress(Warning.NULL_FIELDS) .withOnlyTheseFields("signedMessage") .withPrefabValues(Messages.SignedMessage.class, signedConsensusMessage(red), signedCons... | @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } | ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } } | ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTran... | ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTran... | ParsedTransactionMessage implements TransactionMessage { @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ParsedTransactionMessage)) { return false; } ParsedTransactionMessage that = (ParsedTransactionMessage) o; return signedMessage.equals(that.signedMessage); } ParsedTran... |
@Test void longSerializesAsText() { long value = 10L; String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "10"); } | public static Gson json() { return INSTANCE; } | JsonSerializer { public static Gson json() { return INSTANCE; } } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } |
@Test void publicKeySerializesAsHexValue() { PublicKey value = PublicKey.fromBytes(bytes(0x00, 0x01, 0x02)); String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "000102"); } | public static Gson json() { return INSTANCE; } | JsonSerializer { public static Gson json() { return INSTANCE; } } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } |
@Test void hashCodeSerializesAsValue() { HashCode value = HashCode.fromBytes(bytes(0x00, 0x01, 0x02)); String json = json().toJson(new Wrapper<>(value)); assertJsonValue(json, "000102"); } | public static Gson json() { return INSTANCE; } | JsonSerializer { public static Gson json() { return INSTANCE; } } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } |
@Test void transactionMessageSerializesAsValue() { TransactionMessage value = aMessage(); String json = json().toJson(new Wrapper<>(value)); String expectedValue = Bytes.toHexString(value.toBytes()); assertJsonValue(json, expectedValue); } | public static Gson json() { return INSTANCE; } | JsonSerializer { public static Gson json() { return INSTANCE; } } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } | JsonSerializer { public static Gson json() { return INSTANCE; } private JsonSerializer(); static GsonBuilder builder(); static Gson json(); } |
@Test void parseGetBlockResponse() { String prevHash = "81abde95"; String txHash = "c6c0aa07"; String stateHash = "2eab5971"; String tx1 = "336a4acb"; String tx2 = "12345678"; String commitTime = "2019-10-01T17:07:45.663021Z"; String json = "{\n" + " \"proposer_id\": 0,\n" + " \"height\": 2,\n" + " \"tx_count\": 1,\n" ... | static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } | ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } } | ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private Explo... | ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private Explo... | ExplorerApiHelper { static BlockResponse parseGetBlockResponse(String json) { GetBlockResponse response = JSON.fromJson(json, GetBlockResponse.class); List<HashCode> txs = response.getTxs().stream() .map(IndexedTxHash::getTxHash) .collect(toList()); return new BlockResponse(response.getAsBlock(), txs); } private Explo... |
@Test void toBytes() { Point p = createPoint(-1, 1); assertThat(serializer.toBytes(p), equalTo(p.toByteArray())); } | @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new Asse... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... |
@Test void toBytesIsDeterministic() { Point p1 = createPoint(-1, -1); Point p2 = createPoint(1, 1); Point p3 = createPoint(Integer.MIN_VALUE, Integer.MAX_VALUE); Targets t1 = pointsAsTargetsInOrder(p1, p2, p3); Targets t2 = pointsAsTargetsInOrder(p3, p2, p1); ProtobufReflectiveSerializer<Targets> serializer = new Proto... | @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new Asse... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... |
@Test void toBytesNullMessage() { assertThrows(NullPointerException.class, () -> serializer.toBytes(null)); } | @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpaceLeft(); return result; } catch (IOException e) { throw new Asse... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @Override public byte[] toBytes(MessageT value) { byte[] result = new byte[value.getSerializedSize()]; CodedOutputStream output = CodedOutputStream.newInstance(result); output.useDeterministicSerialization(); try { value.writeTo(output); output.checkNoSpace... |
@Test void fromBytesNull() { assertThrows(NullPointerException.class, () -> serializer.fromBytes(null)); } | @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new Asse... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... |
@Test void fromBytesInvalidInput() { byte[] invalidBuffer = new byte[32]; assertThrows(IllegalArgumentException.class, () -> serializer.fromBytes(invalidBuffer)); } | @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(e); } catch (Throwable throwable) { throw new Asse... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... | ProtobufReflectiveSerializer implements Serializer<MessageT> { @SuppressWarnings("unchecked") @Override public MessageT fromBytes(byte[] serializedValue) { checkNotNull(serializedValue); try { return (MessageT) messageParseFrom.invoke(serializedValue); } catch (InvalidProtocolBufferException e) { throw new IllegalArgum... |
@Test void fromSelf() { assertThat(CheckingSerializerDecorator.from(decorator), sameInstance(decorator)); } | public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } | CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } } | CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private Checkin... | CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private Checkin... | CheckingSerializerDecorator implements Serializer<T> { public static <T> CheckingSerializerDecorator<T> from(Serializer<T> serializer) { if (serializer instanceof CheckingSerializerDecorator) { return (CheckingSerializerDecorator<T>) serializer; } return new CheckingSerializerDecorator<>(serializer); } private Checkin... |
@Test void toBytes() { Object value = new Object(); byte[] valueBytes = new byte[0]; when(delegateMock.toBytes(value)).thenReturn(valueBytes); assertThat(decorator.toBytes(value), equalTo(valueBytes)); } | @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... |
@Test void toBytes_NullValue() { assertThrows(NullPointerException.class, () -> decorator.toBytes(null)); } | @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... |
@Test void toBytes_NullFromDelegate() { when(delegateMock.toBytes(any())).thenReturn(null); expectBrokenSerializerException(() -> decorator.toBytes(new Object())); } | @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... |
@Test void fromBytes() { Object value = new Object(); byte[] valueBytes = new byte[0]; when(delegateMock.fromBytes(valueBytes)).thenReturn(value); assertThat(decorator.fromBytes(valueBytes), equalTo(value)); } | @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... |
@Test void parseGetBlocksResponse() { String json = "{\n" + " 'range': {\n" + " 'start': 6,\n" + " 'end': 288\n" + " },\n" + " 'blocks': [ " + BLOCK_1_JSON + "," + BLOCK_2_JSON + "," + BLOCK_3_JSON + "]\n" + "}\n"; BlocksResponse response = ExplorerApiHelper.parseGetBlocksResponse(json); assertThat(response.getBlocks()... | static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } | ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } } | ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); } | ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); } | ExplorerApiHelper { static BlocksResponse parseGetBlocksResponse(String json) { GetBlocksResponse response = JSON.fromJson(json, GetBlocksResponse.class); return new BlocksResponse( response.getBlocks(), response.getRange().getStart(), response.getRange().getEnd() ); } private ExplorerApiHelper(); } |
@Test void fromBytes_NullValue() { assertThrows(NullPointerException.class, () -> decorator.toBytes(null)); } | @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } } | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... | CheckingSerializerDecorator implements Serializer<T> { @Override public byte[] toBytes(T value) { byte[] valueBytes = delegate.toBytes(checkNotNull(value, "value is null")); checkState(valueBytes != null, "Broken serializer (%s): produces null byte array for a non-null value", delegate); return valueBytes; } private C... |
@Test void fromBytes_NullFromDelegate() { when(delegateMock.fromBytes(any())).thenReturn(null); expectBrokenSerializerException(() -> decorator.fromBytes(new byte[0])); } | @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exception if a serialized value cannot be converted " + "to... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... | CheckingSerializerDecorator implements Serializer<T> { @Override public T fromBytes(byte[] serializedValue) { T value = delegate.fromBytes(checkNotNull(serializedValue, "serializedValue is null")); checkState(value != null, "Broken serializer (%s): produces a null value for a non-null array." + " You must throw an exce... |
@Test void checkArtifactWithNoForbiddenCharacters() { String name = "com.acme/foo:1.0"; checkNoForbiddenChars(name); } | static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); ... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... |
@Test void checkArtifactWithForbiddenCharacters() { String name = "com.acme foo:1.0"; assertThrows(IllegalArgumentException.class, () -> checkNoForbiddenChars(name)); } | static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(), matcher.start())); ... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... | JavaArtifactUtils { static void checkNoForbiddenChars(String artifactId) { Matcher matcher = FORBIDDEN_CHARS_PATTERN.matcher(artifactId); if (matcher.find()) { throw new IllegalArgumentException(String.format("'%s' must not have any forbidden " + "characters, but there is '%s' at index %d", artifactId, matcher.group(),... |
@Test void valueOf() { int runtimeId = 1; String name = "test-service"; String version = "0.1"; ServiceArtifactId id = ServiceArtifactId.valueOf(runtimeId, name, version); assertThat(id.getRuntimeId()).isEqualTo(runtimeId); assertThat(id.getName()).isEqualTo(name); assertThat(id.getVersion()).isEqualTo(version); } | public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } | ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } } | ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } } | ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } abstract int... | ServiceArtifactId { public static ServiceArtifactId valueOf(int runtimeId, String name, String version) { checkArgument(isNotBlank(name), "name is blank: '%s'", name); checkArgument(isNotBlank(version), "version is blank: '%s'", version); return new AutoValue_ServiceArtifactId(runtimeId, name, version); } abstract int... |
@Test void newJavaId() { String name = "test-service"; String version = "test-version"; ServiceArtifactId id = ServiceArtifactId.newJavaId(name, version); assertThat(id.getRuntimeId()).isEqualTo(RuntimeId.JAVA.getId()); assertThat(id.getName()).isEqualTo(name); } | public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } | ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } } | ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } } | ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJav... | ServiceArtifactId { public static ServiceArtifactId newJavaId(String name, String version) { return valueOf(JAVA.getId(), name, version); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJav... |
@Test void fromProto() { ArtifactId artifactId = ARTIFACT_ID; ServiceArtifactId serviceArtifactId = ServiceArtifactId.fromProto(artifactId); assertThat(serviceArtifactId.getRuntimeId()).isEqualTo(artifactId.getRuntimeId()); assertThat(serviceArtifactId.getName()).isEqualTo(artifactId.getName()); assertThat(serviceArtif... | public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } | ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } } | ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } } | ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtif... | ServiceArtifactId { public static ServiceArtifactId fromProto(ArtifactId artifactId) { return valueOf(artifactId.getRuntimeId(), artifactId.getName(), artifactId.getVersion()); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtif... |
@Test void toStringTest() { ServiceArtifactId id = ServiceArtifactId.valueOf(0, "full-name", "0.1"); assertThat(id.toString()).isEqualTo("0:full-name:0.1"); } | @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } | ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } } | ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } } | ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJava... | ServiceArtifactId { @Override public final String toString() { return getRuntimeId() + DELIMITER + getName() + DELIMITER + getVersion(); } abstract int getRuntimeId(); abstract String getName(); abstract String getVersion(); static ServiceArtifactId parseFrom(String serviceArtifactId); static ServiceArtifactId newJava... |
@Test void emptyListValidProof() { FlatListProof proof = new FlatListProof(emptyList(), emptyList(), 0L); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isZero(); assertThat(checked.getIndexHash()).isEqualTo(EMPTY_LIST_INDEX_HASH); } | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void singletonListValidProof() { int index = 0; ListProofElementEntry element = ELEMENT_ENTRIES.get(index); long size = 1L; FlatListProof proof = new FlatListProof(singletonList(element), emptyList(), size); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size(... | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void parseServicesResponse() { String serviceName1 = "service-name-1"; String serviceName2 = "service-name-2"; int serviceId1 = 1; int serviceId2 = 2; ServiceInstanceInfo serviceInstanceInfo1 = new ServiceInstanceInfo(serviceName1, serviceId1); ServiceInstanceInfo serviceInstanceInfo2 = new ServiceInstanceInfo(se... | static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } | ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } } | ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); } | ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); } | ExplorerApiHelper { static List<ServiceInstanceInfo> parseServicesResponse(String json) { ServicesResponse servicesResponse = JSON.fromJson(json, ServicesResponse.class); return servicesResponse.getServices().stream() .map(ServiceInstanceState::getSpec) .collect(toList()); } private ExplorerApiHelper(); } |
@Test void twoElementListValidProofE0() { int index = 0; long size = 2L; ListProofHashedEntry h1 = hashedEntry(1, 0); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(ELEMENT_ENTRIES.get(index)) .addProofEntry(h1) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.is... | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void twoElementListValidProofE1() { int index = 1; long size = 2L; ListProofHashedEntry h0 = hashedEntry(0, 0); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(ELEMENT_ENTRIES.get(index)) .addProofEntry(h0) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.is... | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void twoElementListValidProofFullProof() { long size = 2L; FlatListProof proof = new FlatListProofBuilder() .size(size) .addElements(ELEMENT_ENTRIES.subList(0, (int) size)) .build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.size()).isEqualTo(size); asser... | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void twoElementListValidProofAt0() { FlatListProof proof = twoElementListAt0().build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); } | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void threeElementListValidProofE2() { int index = 2; ListProofElementEntry elementEntry = ELEMENT_ENTRIES.get(index); long size = 3; ListProofHashedEntry h0 = hashedEntry(0, 1); FlatListProof proof = new FlatListProofBuilder() .size(size) .addElement(elementEntry) .addProofEntry(h0) .build(); CheckedListProof<byt... | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void fiveElementListValidProofAt4() { FlatListProof proof = fiveElementListAt4().build(); CheckedListProof<byte[]> checked = proof.verify(); assertTrue(checked.isValid()); assertThat(checked.getElements()).containsExactly(entry(4L, ELEMENTS.get(4))); } | CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProof(); } else { re... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... | FlatListProof { CheckedListProof<byte[]> verify() { if (size < 0 || MAX_SIZE < size) { throw new InvalidProofException(String.format("Invalid size (%s), must be in range [0; 2^56]", size)); } checkProofHashes(); if (size == 0) { return verifyEmptyListProof(); } else if (elements.isEmpty()) { return verifyEmptyRangeProo... |
@Test void checkValidSha256Hash() { HashCode hash = HashCode.fromBytes(new byte[32]); assertDoesNotThrow(() -> ProofHashes.checkSha256Hash(hash)); } | public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } | ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } } | ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); } | ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); static void checkSha256Hash(Hash... | ProofHashes { public static void checkSha256Hash(HashCode hash) { int size = hash.bits(); if (size != Hashing.DEFAULT_HASH_SIZE_BITS) { String message = String.format("Invalid hash size (%s), must be 256 bits", size); throw new InvalidProofException(message); } } private ProofHashes(); static void checkSha256Hash(Hash... |
@Test void throwsIfNull() { assertThrows(NullPointerException.class, () -> DbKey.fromBytes(null)); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfInvalidNodeTypeCode() { byte[] rawDbKey = createDbKey(2, bytes("a"), 8); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfLeafHasInvalidSize() { int invalidNumBits = 10; byte[] rawDbKey = createDbKey(Type.LEAF.code, bytes("a"), invalidNumBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void indexOfFindsTheFirst() { List<Integer> l = ImmutableList.of(-1, 1, 2, 3); Predicate<Integer> positiveInt = i -> i > 0; assertThat(ExonumIterables.indexOf(l, positiveInt), equalTo(OptionalInt.of(1))); } | static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } | ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } } | ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); } | ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); } | ExonumIterables { static <T> OptionalInt indexOf(Iterable<T> list, Predicate<? super T> p) { int i = Iterables.indexOf(list, p::test); if (i == -1) { return OptionalInt.empty(); } return OptionalInt.of(i); } private ExonumIterables(); } |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart0Bits() { int numSignificantBits = 0; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart1Bit() { int numSignificantBits = 1; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x03), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart7Bit() { int numSignificantBits = 7; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0x80), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart8Bit() { int numSignificantBits = 8; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart12Bit() { int numSignificantBits = 12; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0x1F), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void throwsIfBranchKeySliceHasBitsAfterSignificantPart16Bit() { int numSignificantBits = 16; byte[] rawDbKey = createDbKey(Type.BRANCH.code, bytes(0xFF, 0xFF, 0x01), numSignificantBits); assertThrows(IllegalArgumentException.class, () -> { DbKey dbKey = DbKey.fromBytes(rawDbKey); }); } | public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); } | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... | DbKey implements Comparable<DbKey> { public static DbKey fromBytes(byte[] rawDbKey) { return new DbKey(rawDbKey); } private DbKey(byte[] rawDbKey); private DbKey(DbKey.Type nodeType, byte[] keySlice, int numSignificantBits); static DbKey fromBytes(byte[] rawDbKey); static DbKey newLeafKey(ByteString key); static DbKe... |
@Test void mapProofShouldBeCorrect() { DbKey firstDbKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); ByteString valueKey = DbKeyTestUtils.keyByteStringFromString("101110"); DbKey thirdDbKey = DbKeyTestUtils.branchKeyFromPrefix("1011111"); MapEntry<ByteString, ByteString> leaf = createMapEntry(valueKey, FIRST_VALUE);... | @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... |
@Test void mapProofWithSeveralLeafsShouldBeCorrect() { ByteString firstKey = DbKeyTestUtils.keyByteStringFromString("0011_0101"); ByteString secondKey = DbKeyTestUtils.keyByteStringFromString("0011_0110"); DbKey thirdDbKey = DbKeyTestUtils.branchKeyFromPrefix("0100_0000"); ByteString fourthKey = DbKeyTestUtils.keyByteS... | @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... |
@Test void mapProofWithEqualEntriesOrderShouldBeInvalid() { DbKey firstDbKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); DbKey secondKey = DbKeyTestUtils.branchKeyFromPrefix("101100"); List<MapProofEntry> entries = Arrays.asList( createMapProofEntry(firstDbKey), createMapProofEntry(secondKey) ); UncheckedMapProof u... | @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapProofStatus.INVALID_HASH_SIZE); } if (prefixesIncluded... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... | UncheckedFlatMapProof implements UncheckedMapProof { @Override public CheckedMapProof check() { MapProofStatus orderCheckResult = orderCheck(); if (orderCheckResult != MapProofStatus.CORRECT) { return CheckedFlatMapProof.invalid(orderCheckResult); } if (containsInvalidHashes()) { return CheckedFlatMapProof.invalid(MapP... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.