Skip to content

Commit dfd549d

Browse files
Improve tests
1 parent ce8df03 commit dfd549d

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import io.spine.server.BoundedContext;
3333
import io.spine.server.BoundedContextBuilder;
3434
import io.spine.testing.TestValues;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.BeforeEach;
3537
import org.junit.jupiter.api.DisplayName;
3638
import org.junit.jupiter.api.Test;
3739

@@ -61,13 +63,27 @@ class NamespaceIndexTest {
6163

6264
private static final NsConverterFactory converterFactory = NsConverterFactory.defaults();
6365

66+
private NamespaceIndex namespaceIndex;
67+
private BoundedContext context;
68+
6469
private static TenantId newTenantId() {
6570
return TenantId
6671
.newBuilder()
6772
.setValue(TestValues.randomString())
6873
.vBuild();
6974
}
7075

76+
@BeforeEach
77+
void createIndex() {
78+
namespaceIndex = nsIndex();
79+
context = BoundedContextBuilder.assumingTests().build();
80+
}
81+
82+
@AfterEach
83+
void closeContext() throws Exception {
84+
context.close();
85+
}
86+
7187
@Test
7288
@DisplayName(NOT_ACCEPT_NULLS)
7389
void testNulls() {
@@ -77,17 +93,13 @@ void testNulls() {
7793
new NullPointerTester()
7894
.setDefault(Namespace.class, defaultNamespace)
7995
.setDefault(TenantId.class, tenantId)
80-
.setDefault(BoundedContext.class, BoundedContextBuilder.assumingTests()
81-
.build())
82-
.testInstanceMethods(nsIndex(),
83-
NullPointerTester.Visibility.PACKAGE);
96+
.setDefault(BoundedContext.class, context)
97+
.testInstanceMethods(namespaceIndex, NullPointerTester.Visibility.PACKAGE);
8498
}
8599

86100
@Test
87101
@DisplayName("store tenant IDs")
88102
void testStore() {
89-
NamespaceIndex namespaceIndex = nsIndex();
90-
91103
Set<TenantId> initialEmptySet = namespaceIndex.all();
92104
assertTrue(initialEmptySet.isEmpty());
93105

@@ -107,8 +119,6 @@ void testStore() {
107119
@Test
108120
@DisplayName("do nothing on close")
109121
void testClose() {
110-
NamespaceIndex namespaceIndex = nsIndex();
111-
112122
namespaceIndex.close();
113123
namespaceIndex.close();
114124
// No exception is thrown on the second call to #close() => no operation is performed
@@ -117,8 +127,6 @@ void testClose() {
117127
@Test
118128
@DisplayName("find existing namespaces")
119129
void testFindExisting() {
120-
NamespaceIndex namespaceIndex = nsIndex();
121-
122130
// Ensure no namespace has been kept
123131
Set<TenantId> initialEmptySet = namespaceIndex.all();
124132
assertTrue(initialEmptySet.isEmpty());
@@ -133,8 +141,6 @@ void testFindExisting() {
133141
@Test
134142
@DisplayName("not find non-existing namespaces")
135143
void testNotFindNonExisting() {
136-
NamespaceIndex namespaceIndex = nsIndex();
137-
138144
// Ensure no namespace has been kept
139145
Set<TenantId> initialEmptySet = namespaceIndex.all();
140146
assertTrue(initialEmptySet.isEmpty());
@@ -152,6 +158,14 @@ void testAsync() {
152158
NamespaceIndexTest::testSynchronizeAccessMethods);
153159
}
154160

161+
@Test
162+
@DisplayName("confirm registration")
163+
void registered() {
164+
namespaceIndex.registerWith(context);
165+
assertThat(namespaceIndex.isRegistered())
166+
.isTrue();
167+
}
168+
155169
@SuppressWarnings("OverlyLongMethod")
156170
private static void testSynchronizeAccessMethods() throws InterruptedException {
157171
// Initial data

0 commit comments

Comments
 (0)