Skip to content

Commit 1c9fd84

Browse files
Migrate from hamcrest and drop unused dependencies.
1 parent 704d4bb commit 1c9fd84

File tree

3 files changed

+26
-53
lines changed

3 files changed

+26
-53
lines changed

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ subprojects {
134134
name = "spine-server",
135135
version = spineCoreVersion,
136136
classifier = "test")
137-
testImplementation(Deps.test.hamcrest)
138-
testImplementation(Deps.test.guavaTestlib)
139-
testImplementation(Deps.test.junitPioneer)
140137
Deps.test.junit5Api.forEach { testImplementation(it) }
141138
Deps.test.truth.forEach { testImplementation(it) }
142139
testRuntimeOnly(Deps.test.junit5Runner)

datastore/src/test/java/io/spine/server/storage/datastore/NewBoundedContextBuilderTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package io.spine.server.storage.datastore;
2222

2323
import com.google.cloud.datastore.Datastore;
24+
import com.google.common.truth.Truth;
2425
import io.spine.server.BoundedContext;
2526
import io.spine.server.BoundedContextBuilder;
2627
import io.spine.server.storage.datastore.tenant.TestNamespaceIndex;
@@ -31,10 +32,7 @@
3132

3233
import java.util.Optional;
3334

34-
import static org.hamcrest.MatcherAssert.assertThat;
35-
import static org.hamcrest.Matchers.instanceOf;
36-
import static org.junit.jupiter.api.Assertions.assertFalse;
37-
import static org.junit.jupiter.api.Assertions.assertTrue;
35+
import static com.google.common.truth.Truth8.assertThat;
3836

3937
@DisplayName("DatastoreStorageFactory should")
4038
class NewBoundedContextBuilderTest {
@@ -45,14 +43,14 @@ void testProduceBCBuilder() {
4543
DatastoreStorageFactory factory = givenFactory();
4644
BoundedContextBuilder builder = BoundedContext.multitenant(
4745
NewBoundedContextBuilderTest.class.getName());
48-
assertFalse(builder.tenantIndex()
49-
.isPresent());
46+
assertThat(builder.tenantIndex()).isEmpty();
5047

5148
Optional<? extends TenantIndex> updatedIndex =
5249
factory.configureTenantIndex(builder)
5350
.tenantIndex();
54-
assertTrue(updatedIndex.isPresent());
55-
assertThat(updatedIndex.get(), instanceOf(TestNamespaceIndex.getType()));
51+
assertThat(updatedIndex).isPresent();
52+
Truth.assertThat(updatedIndex.get())
53+
.isInstanceOf(TestNamespaceIndex.getType());
5654
}
5755

5856
private static DatastoreStorageFactory givenFactory() {

datastore/src/test/java/io/spine/server/storage/datastore/tenant/SingleTenantNamespaceSupplierTest.java

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@
2323
import io.spine.core.TenantId;
2424
import io.spine.net.EmailAddress;
2525
import io.spine.net.InternetDomain;
26-
import org.hamcrest.BaseMatcher;
27-
import org.hamcrest.Description;
28-
import org.hamcrest.Matcher;
2926
import org.junit.jupiter.api.DisplayName;
3027
import org.junit.jupiter.api.Test;
3128

29+
import static com.google.common.truth.Truth.assertThat;
3230
import static io.spine.protobuf.Messages.isDefault;
33-
import static org.hamcrest.MatcherAssert.assertThat;
34-
import static org.hamcrest.Matchers.isEmptyString;
35-
import static org.hamcrest.Matchers.not;
36-
import static org.junit.jupiter.api.Assertions.assertEquals;
3731
import static org.junit.jupiter.api.Assertions.assertNotNull;
3832

3933
@DisplayName("`SingleTenantNamespaceSupplier` should")
@@ -45,9 +39,9 @@ void testProduceEmpty() {
4539
NamespaceSupplier supplier = NamespaceSupplier.singleTenant();
4640
Namespace namespace = supplier.get();
4741
assertNotNull(namespace);
48-
assertThat(namespace.value(), isEmptyString());
49-
TenantId tenantId = namespace.toTenantId();
50-
assertThat(tenantId, isEffectivelyDefault());
42+
assertThat(namespace.value()).isEmpty();
43+
TenantId tenant = namespace.toTenantId();
44+
assertThat(isEffectivelyDefault(tenant)).isTrue();
5145
}
5246

5347
@Test
@@ -56,40 +50,24 @@ void testProduceCustom() {
5650
String namespaceValue = "my-custom-namespace";
5751
NamespaceSupplier supplier = NamespaceSupplier.singleTenant(namespaceValue);
5852
Namespace namespace = supplier.get();
59-
assertNotNull(namespace);
60-
assertEquals(namespaceValue, namespace.value());
53+
assertThat(namespace).isNotNull();
54+
assertThat(namespace.value()).isEqualTo(namespaceValue);
6155

62-
TenantId tenantId = namespace.toTenantId();
63-
assertThat(tenantId, not(isEffectivelyDefault()));
64-
String actualNamespaceValue = tenantId.getValue();
65-
assertEquals(namespaceValue, actualNamespaceValue);
56+
TenantId tenant = namespace.toTenantId();
57+
assertThat(isEffectivelyDefault(tenant)).isFalse();
58+
assertThat(tenant.getValue()).isEqualTo(namespaceValue);
6659
}
6760

68-
@SuppressWarnings("OverlyComplexAnonymousInnerClass") // OK for the test purposes
69-
private static Matcher<TenantId> isEffectivelyDefault() {
70-
return new BaseMatcher<TenantId>() {
71-
@Override
72-
public boolean matches(Object item) {
73-
if (!(item instanceof TenantId)) {
74-
return false;
75-
}
76-
TenantId tenantId = (TenantId) item;
77-
InternetDomain domain = tenantId.getDomain();
78-
if (!isDefault(domain)) {
79-
return false;
80-
}
81-
EmailAddress email = tenantId.getEmail();
82-
if (!isDefault(email)) {
83-
return false;
84-
}
85-
String value = tenantId.getValue();
86-
return value.isEmpty();
87-
}
88-
89-
@Override
90-
public void describeTo(Description description) {
91-
description.appendText("not default, as expected");
92-
}
93-
};
61+
private static boolean isEffectivelyDefault(TenantId tenant) {
62+
InternetDomain domain = tenant.getDomain();
63+
if (!isDefault(domain)) {
64+
return false;
65+
}
66+
EmailAddress email = tenant.getEmail();
67+
if (!isDefault(email)) {
68+
return false;
69+
}
70+
String value = tenant.getValue();
71+
return value.isEmpty();
9472
}
9573
}

0 commit comments

Comments
 (0)