Skip to content

Commit

Permalink
Use Truth8 instead of Truth for optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrykuzmin committed Sep 3, 2020
1 parent e3a7c76 commit 9789df6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
9 changes: 5 additions & 4 deletions server/src/test/java/io/spine/server/bus/BusFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package io.spine.server.bus;

import com.google.common.testing.NullPointerTester;
import com.google.common.truth.Truth8;
import com.google.protobuf.Message;
import io.spine.base.Error;
import io.spine.core.Ack;
Expand Down Expand Up @@ -71,15 +72,15 @@ void passNullToleranceCheck() {
void letPass() {
BusFilter<CommandEnvelope> filter = new BusFilters.Accepting();
Optional<Ack> ack = filter.filter(commandEnvelope);
assertThat(ack.isPresent()).isFalse();
Truth8.assertThat(ack).isEmpty();
}

@Test
@DisplayName("reject the message with the `OK` status")
void rejectWithOk() {
BusFilter<CommandEnvelope> filter = new BusFilters.RejectingWithOk();
Optional<Ack> ack = filter.filter(commandEnvelope);
assertThat(ack.isPresent()).isTrue();
Truth8.assertThat(ack).isPresent();

Ack theAck = ack.get();
assertIdEquals(theAck);
Expand All @@ -96,7 +97,7 @@ void rejectWithError() {
.build();
BusFilter<CommandEnvelope> filter = new BusFilters.RejectingWithError(error);
Optional<Ack> ack = filter.filter(commandEnvelope);
assertThat(ack.isPresent()).isTrue();
Truth8.assertThat(ack).isPresent();

Ack theAck = ack.get();
assertIdEquals(theAck);
Expand All @@ -116,7 +117,7 @@ void rejectWithThrowableMessage() {
BusFilter<CommandEnvelope> filter =
new BusFilters.RejectingWithThrowableMessage(rejection);
Optional<Ack> ack = filter.filter(commandEnvelope);
assertThat(ack.isPresent()).isTrue();
Truth8.assertThat(ack).isPresent();

Ack theAck = ack.get();
assertIdEquals(theAck);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.testing.NullPointerTester;
import com.google.common.truth.Truth8;
import io.spine.server.entity.storage.given.TaskListViewProjection;
import io.spine.server.entity.storage.given.TaskViewProjection;
import io.spine.server.storage.LifecycleFlagField;
Expand Down Expand Up @@ -57,7 +58,7 @@ void beExtractedFromEntityClass() {
ColumnName columnName = ColumnName.of("description");
Optional<Column> descriptionColumn = columns.find(columnName);

assertThat(descriptionColumn.isPresent()).isTrue();
Truth8.assertThat(descriptionColumn).isPresent();
}

@Test
Expand Down Expand Up @@ -85,7 +86,7 @@ void searchByName() {
ColumnName existent = ColumnName.of("name");
Optional<Column> column = columns.find(existent);

assertThat(column.isPresent()).isTrue();
Truth8.assertThat(column).isPresent();
}

@Test
Expand All @@ -94,7 +95,7 @@ void returnEmptyOptionalForNonExistent() {
ColumnName nonExistent = ColumnName.of("non-existent-column");
Optional<Column> result = columns.find(nonExistent);

assertThat(result.isPresent()).isFalse();
Truth8.assertThat(result).isEmpty();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ void archiveEntityViaMigration() {
repository().applyMigration(id, new MarkPmArchived<>());

Optional<TestProcessManager> found = repository().find(id);
assertThat(found.isPresent()).isTrue();
Truth8.assertThat(found).isPresent();
assertThat(found.get()
.isArchived()).isTrue();
}
Expand All @@ -818,7 +818,7 @@ void deleteEntityViaMigration() {
repository().applyMigration(id, new MarkPmDeleted<>());

Optional<TestProcessManager> found = repository().find(id);
assertThat(found.isPresent()).isTrue();
Truth8.assertThat(found).isPresent();
assertThat(found.get()
.isDeleted()).isTrue();
}
Expand All @@ -833,7 +833,7 @@ void removeRecordViaMigration() {
repository().applyMigration(id, new RemovePmFromStorage<>());

Optional<TestProcessManager> found = repository().find(id);
assertThat(found.isPresent()).isFalse();
Truth8.assertThat(found).isEmpty();
}

private static TargetFilters targetFilters(EntityColumn column, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.truth.Correspondence;
import com.google.common.truth.Truth8;
import com.google.protobuf.Any;
import com.google.protobuf.Timestamp;
import io.spine.base.EntityColumn;
Expand Down Expand Up @@ -698,7 +699,7 @@ void archiveEntityViaMigration() {
repository().applyMigration(id, new MarkProjectionArchived<>());

Optional<TestProjection> found = repository().find(id);
assertThat(found.isPresent()).isTrue();
Truth8.assertThat(found).isPresent();
assertThat(found.get().isArchived()).isTrue();
}

Expand All @@ -712,7 +713,7 @@ void deleteEntityViaMigration() {
repository().applyMigration(id, new MarkProjectionDeleted<>());

Optional<TestProjection> found = repository().find(id);
assertThat(found.isPresent()).isTrue();
Truth8.assertThat(found).isPresent();
assertThat(found.get().isDeleted()).isTrue();
}

Expand All @@ -726,7 +727,7 @@ void removeRecordViaMigration() {
repository().applyMigration(id, new RemoveProjectionFromStorage<>());

Optional<TestProjection> found = repository().find(id);
assertThat(found.isPresent()).isFalse();
Truth8.assertThat(found).isEmpty();
}

private static TargetFilters targetFilters(EntityColumn column, String value) {
Expand Down

0 comments on commit 9789df6

Please sign in to comment.