Skip to content

Commit eb19c27

Browse files
committed
test: migrate to MockitoExtension and clean up test structure
- Replace MockitoAnnotations.openMocks() with @ExtendWith(MockitoExtension.class) - Remove public modifiers from test classes and methods (package-private) - Clean up unnecessary imports and mock stubbings - Ensure proper JUnit 5 + Mockito integration
1 parent 2460689 commit eb19c27

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

powertools-idempotency/powertools-idempotency-dynamodb/src/test/java/software/amazon/lambda/powertools/idempotency/persistence/dynamodb/DynamoDBPersistenceStoreTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
import org.junit.jupiter.api.BeforeEach;
1818
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.extension.ExtendWith;
1920
import org.junitpioneer.jupiter.SetEnvironmentVariable;
2021
import org.mockito.Mock;
21-
import org.mockito.MockitoAnnotations;
22+
import org.mockito.junit.jupiter.MockitoExtension;
2223

2324
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
2425
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
@@ -50,6 +51,7 @@
5051
/**
5152
* Unit tests for DynamoDBPersistenceStore using mocked DynamoDB client.
5253
*/
54+
@ExtendWith(MockitoExtension.class)
5355
class DynamoDBPersistenceStoreTest {
5456
protected static final String TABLE_NAME = "idempotency_table";
5557
private DynamoDBPersistenceStore dynamoDBPersistenceStore;
@@ -59,7 +61,6 @@ class DynamoDBPersistenceStoreTest {
5961

6062
@BeforeEach
6163
void setup() {
62-
MockitoAnnotations.openMocks(this);
6364
dynamoDBPersistenceStore = DynamoDBPersistenceStore.builder()
6465
.withTableName(TABLE_NAME)
6566
.withDynamoDbClient(client)

powertools-idempotency/powertools-idempotency-dynamodb/src/test/java/software/amazon/lambda/powertools/idempotency/persistence/dynamodb/IdempotencyTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
2526
import org.mockito.Mock;
26-
import org.mockito.MockitoAnnotations;
27+
import org.mockito.junit.jupiter.MockitoExtension;
2728

2829
import com.amazonaws.services.lambda.runtime.Context;
2930
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
@@ -42,6 +43,7 @@
4243
import java.util.HashMap;
4344
import java.util.Map;
4445

46+
@ExtendWith(MockitoExtension.class)
4547
class IdempotencyTest {
4648

4749
@Mock
@@ -50,18 +52,13 @@ class IdempotencyTest {
5052
@Mock
5153
private DynamoDbClient client;
5254

53-
@BeforeEach
54-
void setUp() {
55-
MockitoAnnotations.openMocks(this);
56-
}
5755

5856
@Test
5957
void endToEndTest() {
6058
// For this test, we'll simplify and just verify that the function works with mocks
6159
// The important part is that our new mocking approach doesn't break existing functionality
6260

6361
when(client.putItem(any(PutItemRequest.class))).thenReturn(null);
64-
when(client.getItem(any(GetItemRequest.class))).thenReturn(GetItemResponse.builder().build());
6562

6663
IdempotencyFunction function = new IdempotencyFunction(client);
6764

0 commit comments

Comments
 (0)