Skip to content

Commit 392382e

Browse files
committed
test: Add unit test for TableUtils
1 parent 07840c4 commit 392382e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2019-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* https://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package com.dasburo.spring.cache.dynamo.util;
17+
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
20+
import org.mockito.Mock;
21+
import org.mockito.junit.jupiter.MockitoExtension;
22+
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
23+
import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest;
24+
import software.amazon.awssdk.services.dynamodb.model.ResourceInUseException;
25+
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.mockito.ArgumentMatchers.any;
28+
import static org.mockito.Mockito.when;
29+
30+
@ExtendWith(MockitoExtension.class)
31+
class TableUtilsTest {
32+
33+
@Mock
34+
private DynamoDbClient mockDynamoTemplate;
35+
36+
@Test
37+
public void testCreateTableIfNotExists_alreadyExists() {
38+
when(mockDynamoTemplate.createTable(any(CreateTableRequest.class)))
39+
.thenThrow(ResourceInUseException.class);
40+
41+
boolean result = TableUtils.createTableIfNotExists(mockDynamoTemplate, CreateTableRequest.builder().build());
42+
assertFalse(result);
43+
}
44+
}

0 commit comments

Comments
 (0)