diff --git a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/priority/StreamStoreRemappingSweepPriorityCalculatorTest.java b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/priority/StreamStoreRemappingSweepPriorityCalculatorTest.java index 32c50b05ba8..ea3b6f3ab37 100644 --- a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/priority/StreamStoreRemappingSweepPriorityCalculatorTest.java +++ b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/priority/StreamStoreRemappingSweepPriorityCalculatorTest.java @@ -501,17 +501,17 @@ private void whenCalculatingSweepPriorities() { // Then private void thenNoTablesToSweep() { - assertThat(priorities.isEmpty()).isEqualTo(true); + assertThat(priorities).isEmpty(); } private void thenOnlyTablePrioritisedIs(TableReference table) { - assertThat(priorities.size()).isEqualTo(1); - assertThat(priorities.containsKey(table)).isEqualTo(true); + assertThat(priorities).hasSize(1); + assertThat(priorities).containsKey(table); } private void thenOnlyTablePrioritisedIs(SweepPriorityHistory sweepPriorityHistory) { - assertThat(priorities.size()).isEqualTo(1); - assertThat(priorities.containsKey(sweepPriorityHistory.tableRef)).isEqualTo(true); + assertThat(priorities).hasSize(1); + assertThat(priorities).containsKey(sweepPriorityHistory.tableRef); } private void thenTableHasPriority(TableReference table) { @@ -527,7 +527,7 @@ private void thenTableHasZeroPriority(SweepPriorityHistory sweepPriorityHistory) } private void thenNumberOfTablesIs(int expectedNumberOfTables) { - assertThat(priorities.size()).isEqualTo(expectedNumberOfTables); + assertThat(priorities).hasSize(expectedNumberOfTables); } private void thenFirstTableHasHigherPriorityThanSecond( diff --git a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/queue/SweepableCellsTest.java b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/queue/SweepableCellsTest.java index bdce31587d4..8031ce14390 100644 --- a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/queue/SweepableCellsTest.java +++ b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/sweep/queue/SweepableCellsTest.java @@ -318,7 +318,7 @@ public void canReadMultipleEntriesInSingleShardSameTransactionMultipleDedicated( List writes = writeCommittedConservativeRowForTimestamp(TS + 1, MAX_CELLS_DEDICATED + 1); SweepBatch conservativeBatch = readConservative(0, TS_FINE_PARTITION, TS, TS + 2); - assertThat(conservativeBatch.writes()).hasSize(writes.size()); + assertThat(conservativeBatch.writes()).hasSameSizeAs(writes); assertThat(conservativeBatch.writes()).contains(writes.get(0), writes.get(writes.size() - 1)); } diff --git a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/transaction/encoding/TicketsEncodingStrategyTest.java b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/transaction/encoding/TicketsEncodingStrategyTest.java index 960ee3c0cf4..f83c65555ec 100644 --- a/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/transaction/encoding/TicketsEncodingStrategyTest.java +++ b/atlasdb-impl-shared/src/test/java/com/palantir/atlasdb/transaction/encoding/TicketsEncodingStrategyTest.java @@ -169,6 +169,6 @@ private static void assertStartTimestampsCanBeDistinguished(long... timestamps) .boxed() .map(STRATEGY::encodeStartTimestampAsCell) .collect(Collectors.toSet()); - assertThat(convertedCells).hasSize(timestamps.length); + assertThat(convertedCells).hasSameSizeAs(timestamps); } } diff --git a/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/http/JepsenLockClientTest.java b/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/http/JepsenLockClientTest.java index 8085ed7723d..ad9a86024a4 100644 --- a/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/http/JepsenLockClientTest.java +++ b/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/http/JepsenLockClientTest.java @@ -79,7 +79,7 @@ public void refreshSingleCallsRefreshWithMatchingArgument() throws InterruptedEx @Test public void refreshSingleReturnsTokenIfCanBeRefreshed() throws InterruptedException { when(mockClient.refresh(any())).then(REPLY_WITH_FIRST_TOKEN); - assertThat(LOCK_TOKEN).isEqualTo(client.refreshSingle(LOCK_TOKEN)); + assertThat(client.refreshSingle(LOCK_TOKEN)).isEqualTo(LOCK_TOKEN); } @Test diff --git a/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/jepsen/PartitionByInvokeNameCheckerHelperTest.java b/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/jepsen/PartitionByInvokeNameCheckerHelperTest.java index eb85d455741..200db14d199 100644 --- a/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/jepsen/PartitionByInvokeNameCheckerHelperTest.java +++ b/atlasdb-jepsen-tests/src/test/java/com/palantir/atlasdb/jepsen/PartitionByInvokeNameCheckerHelperTest.java @@ -123,7 +123,7 @@ public void partitioningOnlyReordersEvents() { CheckerResult checkerResult = runPartitionChecker(() -> identityChecker, eventList); assertThat(checkerResult.valid()).isFalse(); - assertThat(checkerResult.errors()).hasSize(eventList.size()); + assertThat(checkerResult.errors()).hasSameSizeAs(eventList); assertThat(checkerResult.errors()).containsOnlyElementsOf(eventList); } diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractGetCandidateCellsForSweepingTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractGetCandidateCellsForSweepingTest.java index eff1f4b023c..e766be2c3b3 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractGetCandidateCellsForSweepingTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/keyvalue/impl/AbstractGetCandidateCellsForSweepingTest.java @@ -211,7 +211,7 @@ private void doTestLargerTable(boolean checkIfLatestValueIsEmpty) { } } } - assertThat(expectedCells.size()).isEqualTo((1 + 50) * 50 / 2); + assertThat(expectedCells).hasSize((1 + 50) * 50 / 2); builder.store(); List candidates = getAllCandidates(ImmutableCandidateCellForSweepingRequest.builder() .startRowInclusive(PtBytes.EMPTY_BYTE_ARRAY) diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTaskRunnerTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTaskRunnerTest.java index f1cace2dafa..82282ece565 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTaskRunnerTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTaskRunnerTest.java @@ -117,7 +117,7 @@ public void testSweepBatchesUpToDeleteBatchSize() { runSweep(cellsSweeper, spiedSweepRunner, 8, 1, 4); List> sweptCells = sweptCellsAndSweepResults.getLhSide(); - assertThat(sweptCells.size()).isEqualTo(1); + assertThat(sweptCells).hasSize(1); assertThat(sweptCells.get(0)).isEqualTo(SMALL_LIST_OF_CELLS); } @@ -215,7 +215,7 @@ public void testSweepManyValuesIncludingUncommittedConservative() { assertThat(results.getStaleValuesDeleted()).isEqualTo(4); assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(5); assertThat(getFromDefaultColumn("foo", 200)).isEqualTo("buzz"); - assertThat(getFromDefaultColumn("foo", 124)).isEqualTo(""); + assertThat(getFromDefaultColumn("foo", 124)).isEmpty(); assertThat(getAllTsFromDefaultColumn("foo")).isEqualTo(ImmutableSet.of(-1L, 125L)); } @@ -269,7 +269,7 @@ public void testSweepManyLatestDeletedThoroughIncludingUncommitted1() { // this check is a nuance of SweepTaskRunner: the value at timestamp 125 is actually eligible for deletion, // but we don't delete it on the first pass due to the later uncommitted value. below we sweep again and make // sure it's deleted - assertThat(getFromDefaultColumn("foo", 200)).isEqualTo(""); + assertThat(getFromDefaultColumn("foo", 200)).isEmpty(); assertThat(getAllTsFromDefaultColumn("foo")).isEqualTo(ImmutableSet.of(125L)); results = completeSweep(175).get(); diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTest.java index 89c522c92eb..2e90f870a09 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/sweep/AbstractSweepTest.java @@ -126,7 +126,7 @@ public void testSweepOneConservative() { }); assertThat(getFromDefaultColumn("foo", 150)).isEqualTo("baz"); - assertThat(getFromDefaultColumn("foo", 80)).isEqualTo(""); + assertThat(getFromDefaultColumn("foo", 80)).isEmpty(); assertThat(getAllTsFromDefaultColumn("foo")).isEqualTo(ImmutableSet.of(-1L, 100L)); } @@ -159,7 +159,7 @@ public void testSweepManyValuesConservative() { }); assertThat(getFromDefaultColumn("foo", 200)).isEqualTo("buzz"); - assertThat(getFromDefaultColumn("foo", 124)).isEqualTo(""); + assertThat(getFromDefaultColumn("foo", 124)).isEmpty(); assertThat(getAllTsFromDefaultColumn("foo")).isEqualTo(ImmutableSet.of(-1L, 125L)); } @@ -268,7 +268,7 @@ public void testSweepLatestDeletedMultiValConservative() { assertThat(results.getCellTsPairsExamined()).isGreaterThanOrEqualTo(1); }); - assertThat(getFromDefaultColumn("foo", 150)).isEqualTo(""); + assertThat(getFromDefaultColumn("foo", 150)).isEmpty(); assertThat(getAllTsFromDefaultColumn("foo")).isEqualTo(ImmutableSet.of(-1L, 50L)); } diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractSerializableTransactionTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractSerializableTransactionTest.java index 5358a58ba9f..3e926ba932b 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractSerializableTransactionTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/AbstractSerializableTransactionTest.java @@ -17,9 +17,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -209,12 +209,7 @@ public void testClassicWriteSkew() { withdrawMoney(t2, false, false); t1.commit(); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expected to throw because it is a write skew - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -230,12 +225,7 @@ public void testClassicWriteSkew2() { withdrawMoney(t2, false, false); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test(expected = TransactionFailedRetriableException.class) @@ -263,7 +253,7 @@ public void testConcurrentWriteSkew() throws InterruptedException, BrokenBarrier t2.commit(); try { future.get(); - fail(); + fail("fail"); } catch (ExecutionException e) { throw Throwables.rewrapAndThrowUncheckedException(e.getCause()); } @@ -282,12 +272,7 @@ public void testClassicWriteSkewCell() { withdrawMoney(t2, false, true); t1.commit(); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -303,12 +288,7 @@ public void testClassicWriteSkew2Cell() { withdrawMoney(t2, false, true); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test(expected = TransactionFailedRetriableException.class) @@ -336,7 +316,7 @@ public void testConcurrentWriteSkewCell() throws InterruptedException, BrokenBar t2.commit(); try { future.get(); - fail(); + fail("fail"); } catch (ExecutionException e) { throw Throwables.rewrapAndThrowUncheckedException(e.getCause()); } @@ -350,7 +330,7 @@ private void withdrawMoney(Transaction txn, boolean account, boolean isCellGet) } else { account2 -= 150; } - Assert.assertTrue(account1 + account2 >= 0); + assertThat(account1 + account2 >= 0).isTrue(); if (account) { put(txn, "row1", "col1", String.valueOf(account1)); } else { @@ -376,20 +356,15 @@ public void testCycleWithReadOnly() { put(t1, "row1", "col1", newValue); Transaction t2 = startTransaction(); String row1Get = get(t2, "row1", "col1"); - assertEquals(initialValue, row1Get); + assertThat(row1Get).isEqualTo(initialValue); put(t2, "row2", "col1", row1Get); t1.commit(); Transaction readOnly = startTransaction(); - assertEquals(newValue, get(readOnly, "row1", "col1")); - assertEquals(initialValue, get(readOnly, "row2", "col1")); + assertThat(get(readOnly, "row1", "col1")).isEqualTo(newValue); + assertThat(get(readOnly, "row2", "col1")).isEqualTo(initialValue); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -406,7 +381,7 @@ public void testLargerCycleWithReadOnly() { put(t1, "row1", "col1", newValue); Transaction t2 = startTransaction(); String row1Get = get(t2, "row1", "col1"); - assertEquals(initialValue, row1Get); + assertThat(row1Get).isEqualTo(initialValue); put(t2, "row2", "col1", row1Get); t1.commit(); @@ -414,15 +389,10 @@ public void testLargerCycleWithReadOnly() { put(t3, "row1", "col1", newValue2); t3.commit(); Transaction readOnly = startTransaction(); - assertEquals(newValue2, get(readOnly, "row1", "col1")); - assertEquals(initialValue, get(readOnly, "row2", "col1")); + assertThat(get(readOnly, "row1", "col1")).isEqualTo(newValue2); + assertThat(get(readOnly, "row2", "col1")).isEqualTo(initialValue); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -462,12 +432,7 @@ public void testPhantomReadFail() { put(t2, "row0", "col1", initialValue); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -487,12 +452,7 @@ public void testPhantomReadFail2() { put(t2, "row3", "col1", initialValue); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -512,12 +472,7 @@ public void testCellReadWriteFailure() { put(t2, "row3", "col1", initialValue); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -537,12 +492,7 @@ public void testCellReadWriteFailure2() { put(t2, "row2", "col1", "101"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // this is expectecd to throw because it is a write skew - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -595,16 +545,11 @@ private BatchingVisitable> getRangeRetainingCol(Transaction tx @Test public void testColumnRangeReadUnsupported() { Transaction t1 = startTransaction(); - try { - t1.getRowsColumnRange( + assertThatThrownBy(() -> t1.getRowsColumnRange( TEST_TABLE, ImmutableList.of(PtBytes.toBytes("row1")), new ColumnRangeSelection(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY), - 1); - fail(); - } catch (UnsupportedOperationException e) { - // expected - } + 1)).isInstanceOf(UnsupportedOperationException.class); } @Test @@ -631,7 +576,7 @@ public void testColumnRangeReadWriteConflict_batchingVisitable() { BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1)); // Serializable transaction records only the first column as read. Map.Entry read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values())); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -639,12 +584,7 @@ public void testColumnRangeReadWriteConflict_batchingVisitable() { put(t2, "row1", "col0", "v0_0"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -660,7 +600,7 @@ public void testColumnRangeReadWriteConflict_iterator() { // Serializable transaction records only the first column as read. Map.Entry read = Iterables.getOnlyElement(columnRange.values()).next(); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -668,12 +608,7 @@ public void testColumnRangeReadWriteConflict_iterator() { put(t2, "row1", "col0", "v0_0"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -688,7 +623,7 @@ public void testColumnRangeReadWriteConflictOnNewCell_batchingVisitable() { BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1)); // Serializable transaction records only the first column as read. Map.Entry read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values())); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -697,12 +632,7 @@ public void testColumnRangeReadWriteConflictOnNewCell_batchingVisitable() { put(t2, "row1", "col", "v"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -718,7 +648,7 @@ public void testColumnRangeReadWriteConflictOnNewCell_iterator() { // Serializable transaction records only the first column as read. Map.Entry read = Iterables.getOnlyElement(columnRange.values()).next(); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -727,12 +657,7 @@ public void testColumnRangeReadWriteConflictOnNewCell_iterator() { put(t2, "row1", "col", "v"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -747,7 +672,7 @@ public void testColumnRangeReadWriteNoConflict_batchingVisitable() { BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1)); // Serializable transaction records only the first column as read. Map.Entry read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values())); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -771,7 +696,7 @@ public void testColumnRangeReadWriteNoConflict_iterator() { // Serializable transaction records only the first column as read. Map.Entry read = Iterables.getOnlyElement(columnRange.values()).next(); - assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey()); + assertThat(read.getKey()).isEqualTo(Cell.create(row, PtBytes.toBytes("col0"))); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -791,7 +716,7 @@ public void testColumnRangeReadWriteEmptyRange_batchingVisitable() { TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.toBytes("col"), PtBytes.toBytes("col0"), 1)); - assertNull(BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()))); + assertThat(BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()))).isNull(); // Write to avoid the read only path. put(t1, "row1_1", "col0", "v0"); @@ -799,12 +724,7 @@ public void testColumnRangeReadWriteEmptyRange_batchingVisitable() { put(t2, "row1", "col", "v0"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -824,12 +744,7 @@ public void testColumnRangeReadWriteEmptyRange_iterator() { put(t2, "row1", "col", "v0"); t2.commit(); - try { - t1.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t1.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -903,12 +818,7 @@ public void testColumnRangeReadWriteEndOfRangeWithConflict_batchingVisitable() { put(t3, "row1", "col0", "v0"); t3.commit(); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test @@ -932,12 +842,7 @@ public void testColumnRangeReadWriteEndOfRangeWithConflict_iterator() { put(t3, "row1", "col0", "v0"); t3.commit(); - try { - t2.commit(); - fail(); - } catch (TransactionSerializableConflictException e) { - // expected - } + assertThatThrownBy(() -> t2.commit()).isInstanceOf(TransactionSerializableConflictException.class); } @Test diff --git a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/CommitLockTest.java b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/CommitLockTest.java index 63403e28954..beeb79b7581 100644 --- a/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/CommitLockTest.java +++ b/atlasdb-tests-shared/src/main/java/com/palantir/atlasdb/transaction/impl/CommitLockTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.transaction.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -79,7 +80,7 @@ public void shouldAcquireRowLockIfLocksAtRowLevel(ConflictHandler conflictHandle PreCommitCondition rowLocksAcquired = ignored -> { LockResponse response = acquireRowLock(ROW); - assertFalse(response.wasSuccessful()); + assertThat(response.wasSuccessful()).isFalse(); }; commitWriteWith(rowLocksAcquired, conflictHandler); @@ -91,7 +92,7 @@ public void shouldAcquireCellLockIfLocksAtCellLevel(ConflictHandler conflictHand PreCommitCondition cellLocksAcquired = ignored -> { LockResponse response = acquireCellLock(ROW, COLUMN); - assertFalse(response.wasSuccessful()); + assertThat(response.wasSuccessful()).isFalse(); }; commitWriteWith(cellLocksAcquired, conflictHandler); @@ -103,7 +104,7 @@ public void shouldNotAcquireRowLockIfDoesNotLockAtRowLevel(ConflictHandler confl PreCommitCondition canAcquireRowLock = ignored -> { LockResponse response = acquireRowLock(ROW); - assertTrue(response.wasSuccessful()); + assertThat(response.wasSuccessful()).isTrue(); }; commitWriteWith(canAcquireRowLock, conflictHandler); @@ -116,7 +117,7 @@ public void shouldNotAcquireCellLockIfDoesNotLockAtCellLevel(ConflictHandler con PreCommitCondition canAcquireCellLock = ignored -> { LockResponse response = acquireCellLock(ROW, COLUMN); // current lock implementation allows you to get a cell lock on a row that is already locked - assertTrue(response.wasSuccessful()); + assertThat(response.wasSuccessful()).isTrue(); }; commitWriteWith(canAcquireCellLock, conflictHandler); @@ -130,8 +131,8 @@ public void shouldAcquireRowAndCellLockIfRequiresBoth(ConflictHandler conflictHa LockResponse cellLockResponse = acquireCellLock(ROW, COLUMN); LockResponse rowLockResponse = acquireRowLock(ROW); - assertFalse(cellLockResponse.wasSuccessful()); - assertFalse(rowLockResponse.wasSuccessful()); + assertThat(cellLockResponse.wasSuccessful()).isFalse(); + assertThat(rowLockResponse.wasSuccessful()).isFalse(); }; commitWriteWith(cellAndRowLockAcquired, conflictHandler); @@ -143,7 +144,7 @@ public void canAcquireLockOnMultipleCellsOnSameRow(ConflictHandler conflictHandl PreCommitCondition canAcquireLockOnDifferentCell = ignored -> { LockResponse response = acquireCellLock(ROW, OTHER_COLUMN); - assertTrue(response.wasSuccessful()); + assertThat(response.wasSuccessful()).isTrue(); }; commitWriteWith(canAcquireLockOnDifferentCell, conflictHandler); diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/InMemorySweepTaskRunnerTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/InMemorySweepTaskRunnerTest.java index a7fba0a5892..17a90cc8b7c 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/InMemorySweepTaskRunnerTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/InMemorySweepTaskRunnerTest.java @@ -15,6 +15,8 @@ */ package com.palantir.atlasdb.cleaner; +import static org.assertj.core.api.Assertions.assertThat; + import com.palantir.atlasdb.keyvalue.api.SweepResults; import com.palantir.atlasdb.keyvalue.impl.TestResourceManager; import com.palantir.atlasdb.protos.generated.TableMetadataPersistence; @@ -41,6 +43,6 @@ public void testSweepVeryHighlyVersionedCell() { IntStream.rangeClosed(1, 50_000).forEach(i -> putIntoDefaultColumn("row", RandomStringUtils.random(10), i)); Optional results = completeSweep(TABLE_NAME, 100_000, 1); - Assert.assertEquals(50_000 - 1, results.get().getStaleValuesDeleted()); + assertThat(results.get().getStaleValuesDeleted()).isEqualTo(50_000 - 1); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/PuncherTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/PuncherTest.java index 98e2c13df13..df9f1496b29 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/PuncherTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/cleaner/PuncherTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.cleaner; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import com.google.common.base.Suppliers; @@ -87,35 +88,35 @@ public void test() { Supplier timestampSupplier = puncher.getTimestampSupplier(); timeMillis += 60000L; - assertEquals(Long.MIN_VALUE, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(Long.MIN_VALUE); timeMillis += 60000L; - assertEquals(Long.MIN_VALUE, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(Long.MIN_VALUE); timeMillis += 60000L; final long firstExpectedMillis = timeMillis; puncher.punch(firstPunchTimestamp); timeMillis += 60000L; - assertEquals(firstPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(firstPunchTimestamp); final long secondExpectedMillis = timeMillis; puncher.punch(secondPunchTimestamp); - assertEquals(firstPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(firstPunchTimestamp); timeMillis += 60000L; - assertEquals(secondPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(secondPunchTimestamp); timeMillis += 10L; - assertEquals(secondPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(secondPunchTimestamp); puncher.punch(thirdPunchTimestamp); - assertEquals(secondPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(secondPunchTimestamp); timeMillis += 60000L; - assertEquals(thirdPunchTimestamp, (long) timestampSupplier.get()); + assertThat((long) timestampSupplier.get()).isEqualTo(thirdPunchTimestamp); - assertEquals(firstExpectedMillis, puncherStore.getMillisForTimestamp(firstTimestampToGetMillis)); - assertEquals(secondExpectedMillis, puncherStore.getMillisForTimestamp(secondTimestampToGetMillis)); - assertEquals(secondExpectedMillis, puncherStore.getMillisForTimestamp(thirdTimestampToGetMillis)); + assertThat(puncherStore.getMillisForTimestamp(firstTimestampToGetMillis)).isEqualTo(firstExpectedMillis); + assertThat(puncherStore.getMillisForTimestamp(secondTimestampToGetMillis)).isEqualTo(secondExpectedMillis); + assertThat(puncherStore.getMillisForTimestamp(thirdTimestampToGetMillis)).isEqualTo(secondExpectedMillis); } @Test diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/compress/CompressionUtilsTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/compress/CompressionUtilsTest.java index a99ef70426c..b52b2f929a7 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/compress/CompressionUtilsTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/compress/CompressionUtilsTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.compress; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -29,23 +30,23 @@ public void testCompressAndDecompress() { byte[] original = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; byte[] compressed = CompressionUtils.compress(original, Compression.NONE); - assertArrayEquals(original, compressed); + assertThat(compressed).isEqualTo(original); byte[] decompressed = CompressionUtils.decompress(compressed, Compression.NONE); - assertArrayEquals(original, decompressed); + assertThat(decompressed).isEqualTo(original); compressed = CompressionUtils.compress(original, Compression.SNAPPY); - assertFalse(Arrays.equals(original, compressed)); + assertThat(Arrays.equals(original, compressed)).isFalse(); decompressed = CompressionUtils.decompress(compressed, Compression.SNAPPY); - assertArrayEquals(original, decompressed); + assertThat(decompressed).isEqualTo(original); } @Test public void testCompressAndDecompressWithSnappy() { byte[] original = new byte[1024]; byte[] compressed = CompressionUtils.compressWithSnappy(original); - assertFalse(Arrays.equals(original, compressed)); + assertThat(Arrays.equals(original, compressed)).isFalse(); byte[] decompressed = CompressionUtils.decompressWithSnappy(compressed); - assertArrayEquals(original, decompressed); + assertThat(decompressed).isEqualTo(original); } @Test @@ -57,7 +58,7 @@ public void testDecompressException() { } catch (IllegalArgumentException e) { threwIllegalArgumentException = true; } - assertTrue(threwIllegalArgumentException); + assertThat(threwIllegalArgumentException).isTrue(); } @Test @@ -69,6 +70,6 @@ public void testDecompressExceptionWithSnappy() { } catch (IllegalArgumentException e) { threwIllegalArgumentException = true; } - assertTrue(threwIllegalArgumentException); + assertThat(threwIllegalArgumentException).isTrue(); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestTest.java index 4146f6fa56f..c38fa6a3f8d 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.keyvalue.impl; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import com.palantir.atlasdb.keyvalue.api.RangeRequest; @@ -27,18 +28,18 @@ public class RangeRequestTest { @Test public void testPrefix() { byte[] end = RangeRequest.builder().prefixRange(new byte[] {-1}).build().getEndExclusive(); - assertEquals(0, end.length); + assertThat(end.length).isEqualTo(0); end = RangeRequest.builder().prefixRange(new byte[] {-2}).build().getEndExclusive(); - assertEquals(1, end.length); - assertEquals(-1, end[0]); + assertThat(end.length).isEqualTo(1); + assertThat(end[0]).isEqualTo(-1); end = RangeRequest.builder().prefixRange(new byte[] {0, -1}).build().getEndExclusive(); - assertEquals(1, end.length); - assertEquals(1, end[0]); + assertThat(end.length).isEqualTo(1); + assertThat(end[0]).isEqualTo(1); end = RangeRequest.builder().prefixRange(new byte[] {0, -1, 0}).build().getEndExclusive(); - assertEquals(3, end.length); - assertEquals(1, end[2]); + assertThat(end.length).isEqualTo(3); + assertThat(end[2]).isEqualTo(1); } @Test @@ -46,10 +47,10 @@ public void testEmpty() { RangeRequest request = RangeRequest.builder() .endRowExclusive(RangeRequests.getFirstRowName()) .build(); - Assert.assertTrue(request.isEmptyRange()); + assertThat(request.isEmptyRange()).isTrue(); request = RangeRequest.reverseBuilder() .endRowExclusive(RangeRequests.getLastRowName()) .build(); - Assert.assertTrue(request.isEmptyRange()); + assertThat(request.isEmptyRange()).isTrue(); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestsTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestsTest.java index df4a35e1cf9..ae6953fbf19 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestsTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/RangeRequestsTest.java @@ -115,9 +115,7 @@ private byte[] generateRandomWithFreqLogLen() { } private void assertNextPrevEqualsOrig(byte[] value) { - Assert.assertTrue(Arrays.equals( - value, RangeRequests.nextLexicographicName(RangeRequests.previousLexicographicName(value)))); - Assert.assertTrue(Arrays.equals( - value, RangeRequests.previousLexicographicName(RangeRequests.nextLexicographicName(value)))); + assertThat(value).isEqualTo(RangeRequests.nextLexicographicName(RangeRequests.previousLexicographicName(value))); + assertThat(value).isEqualTo(RangeRequests.previousLexicographicName(RangeRequests.nextLexicographicName(value))); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TableTasksTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TableTasksTest.java index 9d9433aad8e..4bfa53ab3a4 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TableTasksTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TableTasksTest.java @@ -15,6 +15,8 @@ */ package com.palantir.atlasdb.keyvalue.impl; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.common.base.Suppliers; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMap; @@ -175,11 +177,11 @@ public void testDiffTask() throws InterruptedException { } } - Assert.assertEquals(commonCells, cellsInCommon.get()); - Assert.assertEquals(sourceOnlyCells, cellsOnlyInSource.get()); - Assert.assertEquals(disjointRows, rowsOnlyInSource.get()); - Assert.assertEquals(commonRows, rowsCompletelyInCommon.get()); - Assert.assertEquals(partialRows, rowsPartiallyInCommon.get()); - Assert.assertEquals(keys1.keySet().size(), rowsVisited.get()); + assertThat(cellsInCommon.get()).isEqualTo(commonCells); + assertThat(cellsOnlyInSource.get()).isEqualTo(sourceOnlyCells); + assertThat(rowsOnlyInSource.get()).isEqualTo(disjointRows); + assertThat(rowsCompletelyInCommon.get()).isEqualTo(commonRows); + assertThat(rowsPartiallyInCommon.get()).isEqualTo(partialRows); + assertThat(rowsVisited.get()).isEqualTo(keys1.keySet().size()); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TracingKvsTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TracingKvsTest.java index e3f848c286f..1f023b06c08 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TracingKvsTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/keyvalue/impl/TracingKvsTest.java @@ -63,15 +63,15 @@ public void tearDown() throws Exception { spans.size(), spans.stream().map(Span::getOperation).collect(Collectors.toList())); if (Tracer.isTraceObservable()) { - assertThat(finishedSpan.isPresent()).isTrue(); + assertThat(finishedSpan).isPresent(); assertThat(finishedSpan.get().getOperation()).isEqualTo("test"); String traceId = finishedSpan.get().getTraceId(); assertThat(traceId).isNotNull(); assertThat(traceId).isNotEmpty(); assertThat(spans).isNotEmpty(); - assertThat(spans.size()) + assertThat(spans) .describedAs("Should include root test span and additional KVS method spans %s", spans) - .isGreaterThanOrEqualTo(1); + .hasSizeGreaterThanOrEqualTo(1); assertThat(spans.stream() .filter(span -> !Objects.equals(traceId, span.getTraceId())) .map(Span::getTraceId) diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/ptobject/EncodingUtilsTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/ptobject/EncodingUtilsTest.java index 8d8a558672a..f2ee3f2f4b3 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/ptobject/EncodingUtilsTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/ptobject/EncodingUtilsTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.ptobject; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -47,8 +48,8 @@ public void testBasicFlipBits() { byte[] ffFlipped = EncodingUtils.flipAllBits(ff); byte[] ooFlipped = EncodingUtils.flipAllBits(oo); - assertArrayEquals(oo, ffFlipped); - assertArrayEquals(ff, ooFlipped); + assertThat(ffFlipped).isEqualTo(oo); + assertThat(ooFlipped).isEqualTo(ff); } @Test @@ -56,7 +57,7 @@ public void testFlipBits() { byte[] bytes = new byte[1000]; for (int i = 0; i < 100; i++) { rand.nextBytes(bytes); - assertArrayEquals(bytes, EncodingUtils.flipAllBits(EncodingUtils.flipAllBits(bytes))); + assertThat(EncodingUtils.flipAllBits(EncodingUtils.flipAllBits(bytes))).isEqualTo(bytes); } } @@ -66,41 +67,39 @@ public void testVarString() throws Exception { byte[] bytes = new byte[1000]; rand.nextBytes(bytes); String str = new String(bytes); - assertArrayEquals( - str.getBytes(), - EncodingUtils.decodeVarString(EncodingUtils.encodeVarString(str)) - .getBytes()); - assertEquals(EncodingUtils.sizeOfVarString(str), EncodingUtils.encodeVarString(str).length); + assertThat(EncodingUtils.decodeVarString(EncodingUtils.encodeVarString(str)) + .getBytes()).isEqualTo(str.getBytes()); + assertThat(EncodingUtils.encodeVarString(str).length).isEqualTo(EncodingUtils.sizeOfVarString(str)); } } @Test public void testVarSimple() { - assertEquals(Long.MIN_VALUE, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(Long.MIN_VALUE))); - assertEquals(-2L, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(-2))); - assertEquals(-1L, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(-1))); - assertEquals(0L, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(0))); - assertEquals(1L, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(1))); - assertEquals(2L, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(2))); - assertEquals(Long.MAX_VALUE, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(Long.MAX_VALUE))); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(Long.MIN_VALUE))).isEqualTo(Long.MIN_VALUE); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(-2))).isEqualTo(-2L); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(-1))).isEqualTo(-1L); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(0))).isEqualTo(0L); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(1))).isEqualTo(1L); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(2))).isEqualTo(2L); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(Long.MAX_VALUE))).isEqualTo(Long.MAX_VALUE); for (int i = 0; i < 1000; i++) { long nextLong = rand.nextLong(); - assertEquals(nextLong, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(); - assertEquals(nextLong, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(1 << 20); - assertEquals(nextLong, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(1 << 10); - assertEquals(nextLong, EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))); + assertThat(EncodingUtils.decodeVarLong(EncodingUtils.encodeVarLong(nextLong))).isEqualTo(nextLong); } } @@ -140,8 +139,8 @@ public void testVarOrder() { long last = 0; for (Map.Entry e : map.entrySet()) { long l = e.getValue(); - assertEquals(l, EncodingUtils.decodeVarLong(e.getKey())); - assertTrue(Arrays.equals(e.getKey(), EncodingUtils.encodeVarLong(l))); + assertThat(EncodingUtils.decodeVarLong(e.getKey())).isEqualTo(l); + assertThat(e.getKey()).isEqualTo(EncodingUtils.encodeVarLong(l)); if (l < last) { String lString = PtBytes.encodeHexString(EncodingUtils.encodeVarLong(l)); String lastString = PtBytes.encodeHexString(EncodingUtils.encodeVarLong(last)); @@ -154,33 +153,31 @@ public void testVarOrder() { @Test public void testVarSigned() { - assertEquals( - Long.MIN_VALUE, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(Long.MIN_VALUE))); - assertEquals(-2L, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(-2))); - assertEquals(-1L, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(-1))); - assertEquals(0L, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(0))); - assertEquals(1L, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(1))); - assertEquals(2L, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(2))); - assertEquals( - Long.MAX_VALUE, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(Long.MAX_VALUE))); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(Long.MIN_VALUE))).isEqualTo(Long.MIN_VALUE); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(-2))).isEqualTo(-2L); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(-1))).isEqualTo(-1L); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(0))).isEqualTo(0L); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(1))).isEqualTo(1L); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(2))).isEqualTo(2L); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(Long.MAX_VALUE))).isEqualTo(Long.MAX_VALUE); for (int i = 0; i < 1000; i++) { long nextLong = rand.nextLong(); - assertEquals(nextLong, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(); - assertEquals(nextLong, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(1 << 20); - assertEquals(nextLong, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))).isEqualTo(nextLong); } for (int i = 0; i < 1000; i++) { long nextLong = rand.nextInt(1 << 10); - assertEquals(nextLong, EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))); + assertThat(EncodingUtils.decodeSignedVarLong(EncodingUtils.encodeSignedVarLong(nextLong))).isEqualTo(nextLong); } } @@ -196,7 +193,7 @@ public void testMultipleVarSigned() { int index = 0; for (int i = 0; i < 1000; i++) { - assertEquals(longs[i], EncodingUtils.decodeSignedVarLong(b, index)); + assertThat(EncodingUtils.decodeSignedVarLong(b, index)).isEqualTo(longs[i]); index += EncodingUtils.sizeOfSignedVarLong(longs[i]); } } @@ -237,8 +234,8 @@ public void testVarSignedOrder() { long last = Long.MIN_VALUE; for (Map.Entry e : map.entrySet()) { long l = e.getValue(); - assertEquals(l, EncodingUtils.decodeSignedVarLong(e.getKey())); - assertTrue(Arrays.equals(e.getKey(), EncodingUtils.encodeSignedVarLong(l))); + assertThat(EncodingUtils.decodeSignedVarLong(e.getKey())).isEqualTo(l); + assertThat(e.getKey()).isEqualTo(EncodingUtils.encodeSignedVarLong(l)); if (l < last) { String lString = PtBytes.encodeHexString(EncodingUtils.encodeVarLong(l)); String lastString = PtBytes.encodeHexString(EncodingUtils.encodeVarLong(last)); @@ -285,7 +282,7 @@ public void testMulti() { List result = EncodingUtils.fromBytes(b, types); - assertEquals(components, result); + assertThat(result).isEqualTo(components); } } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/AbstractTaskCheckpointerTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/AbstractTaskCheckpointerTest.java index d2efa046ff6..70e6f45c57e 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/AbstractTaskCheckpointerTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/AbstractTaskCheckpointerTest.java @@ -15,6 +15,8 @@ */ package com.palantir.atlasdb.schema; +import static org.assertj.core.api.Assertions.assertThat; + import com.palantir.atlasdb.AtlasDbTestCase; import com.palantir.atlasdb.transaction.api.Transaction; import com.palantir.atlasdb.transaction.api.TransactionTask; @@ -100,7 +102,7 @@ public void testEnd() { txManager.runTaskWithRetry((TransactionTask) txn -> { for (long rangeId : next1.keySet()) { byte[] oldCheckpoint = checkpointer.getCheckpoint(t1, rangeId, txn); - Assert.assertNull(oldCheckpoint); + assertThat(oldCheckpoint).isNull(); } return null; }); @@ -121,7 +123,7 @@ private void verifyCheckpoints(final String extraId, final Map sta for (Map.Entry e : startById.entrySet()) { byte[] oldCheckpoint = checkpointer.getCheckpoint(extraId, e.getKey(), txn); byte[] currentCheckpoint = e.getValue(); - Assert.assertTrue(Arrays.equals(oldCheckpoint, currentCheckpoint)); + assertThat(oldCheckpoint).isEqualTo(currentCheckpoint); } } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/NamespaceTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/NamespaceTest.java index 345b56cbc8a..0361d4b1b5b 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/NamespaceTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/NamespaceTest.java @@ -15,7 +15,8 @@ */ package com.palantir.atlasdb.schema; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; import com.palantir.atlasdb.keyvalue.api.Namespace; import java.util.regex.Pattern; @@ -28,12 +29,7 @@ private void expectSuccess(String string, Pattern pattern) { } private void expectFailure(String string, Pattern pattern) { - try { - Namespace.create(string, pattern); - fail("Namespace '" + string + "' was not supposed to match pattern '" + pattern + "'"); - } catch (Exception e) { - // success - } + assertThatThrownBy(() -> Namespace.create(string, pattern)).describedAs("Namespace '" + string + "' was not supposed to match pattern '" + pattern + "'").isInstanceOf(Exception.class); } @Test diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/TableMigratorTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/TableMigratorTest.java index da1c8b3d96f..13fbf3205e0 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/TableMigratorTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/TableMigratorTest.java @@ -15,6 +15,10 @@ */ package com.palantir.atlasdb.schema; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; @@ -53,12 +57,7 @@ public class TableMigratorTest extends AtlasDbTestCase { @Test public void testNeedArguments() { TableMigratorBuilder builder = new TableMigratorBuilder(); - try { - builder.build(); - Assert.fail(); - } catch (Exception e) { - // expected - } + assertThatThrownBy(() -> builder.build()).isInstanceOf(Exception.class); } @SuppressWarnings({"checkstyle:Indentation", "checkstyle:RightCurly"}) // Table/IndexDefinition syntax @@ -156,8 +155,8 @@ public void testMigrationToDifferentKvs() throws TableMappingNotFoundException { public boolean visit(RowResult item) throws RuntimeException { Iterable> cells = item.getCells(); Map.Entry entry = Iterables.getOnlyElement(cells); - Assert.assertEquals(theCell, entry.getKey()); - Assert.assertArrayEquals(theValue, entry.getValue()); + assertThat(entry.getKey()).isEqualTo(theCell); + assertThat(entry.getValue()).isEqualTo(theValue); count.increment(); return true; } @@ -165,6 +164,6 @@ public boolean visit(RowResult item) throws RuntimeException { return null; }); } - Assert.assertEquals(2L, count.longValue()); + assertThat(count.longValue()).isEqualTo(2L); } } diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/indexing/IndexTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/indexing/IndexTest.java index d44f6fe2257..feaf0e54231 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/indexing/IndexTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/indexing/IndexTest.java @@ -15,6 +15,7 @@ */ package com.palantir.atlasdb.schema.indexing; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import com.google.common.collect.HashMultimap; @@ -66,9 +67,9 @@ public void testAddDelete() { DataTable.Index2IdxTable.of(getTableFactory().getDataTable(txn)); DataTable.Index3IdxTable index3 = DataTable.Index3IdxTable.of(getTableFactory().getDataTable(txn)); - assert index1.getRange(RangeRequest.builder().build()).count() == 1; - assert index2.getRange(RangeRequest.builder().build()).count() == 2; - assert index3.getRange(RangeRequest.builder().build()).count() == 1; + assertThat(index1.getRange(RangeRequest.builder().build()).count() == 1).isTrue(); + assertThat(index2.getRange(RangeRequest.builder().build()).count() == 2).isTrue(); + assertThat(index3.getRange(RangeRequest.builder().build()).count() == 1).isTrue(); return null; }); txManager.runTaskWithRetry((RuntimeTransactionTask) txn -> { @@ -83,9 +84,9 @@ public void testAddDelete() { DataTable.Index2IdxTable.of(getTableFactory().getDataTable(txn)); DataTable.Index3IdxTable index3 = DataTable.Index3IdxTable.of(getTableFactory().getDataTable(txn)); - assert index1.getRange(RangeRequest.builder().build()).count() == 1; - assert index2.getRange(RangeRequest.builder().build()).count() == 1; - assert index3.getRange(RangeRequest.builder().build()).count() == 1; + assertThat(index1.getRange(RangeRequest.builder().build()).count() == 1).isTrue(); + assertThat(index2.getRange(RangeRequest.builder().build()).count() == 1).isTrue(); + assertThat(index3.getRange(RangeRequest.builder().build()).count() == 1).isTrue(); return null; }); } @@ -100,11 +101,9 @@ public void testUpdate() { txManager.runTaskWithRetry((RuntimeTransactionTask) txn -> { DataTable.Index1IdxTable index1 = DataTable.Index1IdxTable.of(getTableFactory().getDataTable(txn)); - assertEquals( - 1L, - Iterables.getOnlyElement(index1.getRowColumns(Index1IdxRow.of(2L))) + assertThat(Iterables.getOnlyElement(index1.getRowColumns(Index1IdxRow.of(2L))) .getColumnName() - .getId()); + .getId()).isEqualTo(1L); return null; }); txManager.runTaskWithRetry((RuntimeTransactionTask) txn -> { @@ -115,7 +114,7 @@ public void testUpdate() { txManager.runTaskWithRetry((RuntimeTransactionTask) txn -> { DataTable.Index1IdxTable index1 = DataTable.Index1IdxTable.of(getTableFactory().getDataTable(txn)); - assert index1.getRowColumns(Index1IdxRow.of(2L)).isEmpty(); + assertThat(index1.getRowColumns(Index1IdxRow.of(2L))).isEmpty(); return null; }); } @@ -139,7 +138,7 @@ public void testTwoColumns() { txManager.runTaskWithRetry((RuntimeTransactionTask) txn -> { FooToIdIdxTable index = FooToIdIdxTable.of(getTableFactory().getTwoColumnsTable(txn)); List result = index.getAllRowsUnordered().immutableCopy(); - assertEquals(2L, Iterables.getOnlyElement(result).getRowName().getFoo()); + assertThat(Iterables.getOnlyElement(result).getRowName().getFoo()).isEqualTo(2L); return null; }); } @@ -157,7 +156,7 @@ public void testFirstRowComponentIsHashed() { byte[] firstComponentOfRow = Arrays.copyOf(persistedRow, 8); // We're only interested in the first 8 bytes. - Assert.assertArrayEquals(expected, firstComponentOfRow); + assertThat(firstComponentOfRow).isEqualTo(expected); } private IndexTestTableFactory getTableFactory() { diff --git a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/stream/StreamTest.java b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/stream/StreamTest.java index dd519f77683..998f160124a 100644 --- a/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/stream/StreamTest.java +++ b/atlasdb-tests-shared/src/test/java/com/palantir/atlasdb/schema/stream/StreamTest.java @@ -15,6 +15,9 @@ */ package com.palantir.atlasdb.schema.stream; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -23,9 +26,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; @@ -143,10 +144,10 @@ public void testAddDelete() throws Exception { }); txManager.runTaskWithRetry((TransactionTask) t -> { Optional inputStream = defaultStore.loadSingleStream(t, streamId); - assertTrue(inputStream.isPresent()); + assertThat(inputStream).isPresent(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); outputStream.write(inputStream.get()); - assertArrayEquals(data, outputStream.toByteArray()); + assertThat(outputStream.toByteArray()).isEqualTo(data); return null; }); } @@ -161,7 +162,7 @@ public void testLoadStreamWithWrongId() throws Exception { return defaultStore.getByHashOrStoreStreamAndMarkAsUsed(t, hash, new ByteArrayInputStream(data), reference); }); txManager.runTaskWithRetry((TransactionTask) t -> { - assertThat(defaultStore.loadSingleStream(t, streamId ^ 1L), is(Optional.empty())); + assertThat(defaultStore.loadSingleStream(t, streamId ^ 1L)).isNotPresent(); return null; }); } @@ -172,7 +173,7 @@ public void testStreamStoreWithHashValueRowPersistToBytesAndHydrateSucceeds() { byte[] persistedRow = row.persistToBytes(); StreamTestWithHashStreamValueRow hydratedRow = StreamTestWithHashStreamValueRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -181,7 +182,7 @@ public void testStreamStoreWithHashMetadataRowPersistToBytesAndHydrateSucceeds() byte[] persistedRow = row.persistToBytes(); StreamTestWithHashStreamMetadataRow hydratedRow = StreamTestWithHashStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -190,7 +191,7 @@ public void testStreamStoreWithHashIdxRowPersistToBytesAndHydrateSucceeds() { byte[] persistedRow = row.persistToBytes(); StreamTestWithHashStreamIdxRow hydratedRow = StreamTestWithHashStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -199,7 +200,7 @@ public void testHashRowComponentsValueTable() { byte[] persistedRow = row.persistToBytes(); TestHashComponentsStreamValueRow hydratedRow = TestHashComponentsStreamValueRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -208,7 +209,7 @@ public void testHashRowComponentsMetadataTable() { byte[] persistedRow = row.persistToBytes(); TestHashComponentsStreamMetadataRow hydratedRow = TestHashComponentsStreamMetadataRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -217,7 +218,7 @@ public void testHashRowComponentsIdxTable() { byte[] persistedRow = row.persistToBytes(); TestHashComponentsStreamIdxRow hydratedRow = TestHashComponentsStreamIdxRow.BYTES_HYDRATOR.hydrateFromBytes(persistedRow); - assertEquals(row, hydratedRow); + assertThat(hydratedRow).isEqualTo(row); } @Test @@ -336,7 +337,7 @@ private void verifyLoadStream(PersistentStreamStore store, long id, byte[] bytes private void verifyLoadSingleStream(PersistentStreamStore store, long id, byte[] toStore) throws IOException { Optional stream = txManager.runTaskThrowOnConflict(t -> store.loadSingleStream(t, id)); - assertTrue(stream.isPresent()); + assertThat(stream).isPresent(); assertStreamHasBytes(stream.get(), toStore); } @@ -348,12 +349,12 @@ private void verifyLoadStreams(PersistentStreamStore store, long id, byte[] byte private void verifyLoadStreamAsFile(PersistentStreamStore store, long id, byte[] bytesToStore) throws IOException { File file = txManager.runTaskThrowOnConflict(t -> store.loadStreamAsFile(t, id)); - assertArrayEquals(bytesToStore, FileUtils.readFileToByteArray(file)); + assertThat(FileUtils.readFileToByteArray(file)).isEqualTo(bytesToStore); } private void assertStreamHasBytes(InputStream stream, byte[] bytes) throws IOException { byte[] streamAsBytes = IOUtils.toByteArray(stream); - assertArrayEquals(bytes, streamAsBytes); + assertThat(streamAsBytes).isEqualTo(bytes); stream.close(); } @@ -574,9 +575,9 @@ id1, new ByteArrayInputStream(bytes1), Map sha256HashLongMap = txManager.runTaskWithRetry( t -> defaultStore.lookupStreamIdsByHash(t, ImmutableSet.of(hash1, hash2, hash3))); - assertEquals(id1, sha256HashLongMap.get(hash1).longValue()); - assertEquals(id2, sha256HashLongMap.get(hash2).longValue()); - assertNull(sha256HashLongMap.get(hash3)); + assertThat(sha256HashLongMap.get(hash1).longValue()).isEqualTo(id1); + assertThat(sha256HashLongMap.get(hash2).longValue()).isEqualTo(id2); + assertThat(sha256HashLongMap.get(hash3)).isNull(); } @Test @@ -590,7 +591,7 @@ public void readingStreamIdsByHashInTheSameTransactionIsPermitted() throws IOExc storeStreamAndCheckHash(id, hash, streams); byte[] bytesInKvs = readBytesForSingleStream(id); - assertArrayEquals(bytesInKvs, bytes); + assertThat(bytes).isEqualTo(bytesInKvs); } @Test @@ -605,7 +606,7 @@ public void streamsAreNotReused() throws IOException { storeStreamAndCheckHash(id, hash, streams); byte[] bytesInKvs = readBytesForSingleStream(id); - assertArrayEquals(bytesInKvs, bytes); + assertThat(bytes).isEqualTo(bytesInKvs); } @Test @@ -624,8 +625,8 @@ id1, new ByteArrayInputStream(bytes), Pair idAndHash1 = defaultStore.storeStream(new ByteArrayInputStream(bytes)); Pair idAndHash2 = defaultStore.storeStream(new ByteArrayInputStream(bytes)); - assertThat(idAndHash1.getRhSide(), equalTo(idAndHash2.getRhSide())); // verify hashes are the same - assertThat(idAndHash1.getLhSide(), not(equalTo(idAndHash2.getLhSide()))); // verify ids are different + assertThat(idAndHash1.getRhSide()).isEqualTo(idAndHash2.getRhSide()); // verify hashes are the same + assertThat(idAndHash1.getLhSide()).isNotEqualTo(idAndHash2.getLhSide()); // verify ids are different } @Test @@ -670,8 +671,8 @@ public void startSecondAndFinish(Transaction tx, long streamId) { }); Optional stream = getStream(streamId); - assertTrue(stream.isPresent()); - assertNotNull(stream.get()); + assertThat(stream).isPresent(); + assertThat(stream.get()).isNotNull(); } @Test @@ -683,7 +684,7 @@ public void testStreamCompression() throws IOException { long id = storeStream(compressedStore, input, PtBytes.toBytes("ref")); long numBlocksUsed = getStreamBlockSize(getStreamMetadata(id)); - assertEquals(expectedBlocksUsed, numBlocksUsed); + assertThat(numBlocksUsed).isEqualTo(expectedBlocksUsed); } private byte[] generateRandomTwoBlockStream() { @@ -717,7 +718,7 @@ private Optional getStream(long streamId) { private void storeStreamAndCheckHash(long id, Sha256Hash hash, Map streams) { txManager.runTaskWithRetry(t -> { Map hashes = defaultStore.storeStreams(t, streams); - assertEquals(hash, hashes.get(id)); + assertThat(hashes.get(id)).isEqualTo(hash); return null; }); } @@ -730,7 +731,7 @@ private byte[] readBytesForSingleStream(long id) throws IOException { } private void assertStreamDoesNotExist(final long streamId) { - assertFalse("This element should have been deleted", getStream(streamId).isPresent()); + assertThat(getStream(streamId)).describedAs("This element should have been deleted").isNotPresent(); } private void runConflictingTasksConcurrently(long streamId, TwoConflictingTasks tasks) throws InterruptedException { @@ -740,16 +741,11 @@ private void runConflictingTasksConcurrently(long streamId, TwoConflictingTasks ExecutorService exec = PTExecutors.newFixedThreadPool(2); Future firstFuture = exec.submit(() -> { - try { - txManager.runTaskThrowOnConflict(t -> { + assertThatThrownBy(() -> txManager.runTaskThrowOnConflict(t -> { tasks.startFirstAndFail(t, streamId); letOtherTaskFinish(firstLatch, secondLatch); return null; - }); - fail("Because we concurrently wrote, we should have failed with TransactionConflictException."); - } catch (TransactionConflictException e) { - // expected - } + })).describedAs("Because we concurrently wrote, we should have failed with TransactionConflictException.").isInstanceOf(TransactionConflictException.class); }); firstLatch.await();