Skip to content

Commit d5b2097

Browse files
committed
fix: address SonarLint issues
- Remove public modifiers from test classes and methods (JUnit5 package-private scope) - Remove unused imports (ResourceNotFoundException, Collections) - Remove unnecessary E2E test method for better scope focus
1 parent 71817d8 commit d5b2097

File tree

4 files changed

+13
-28
lines changed

4 files changed

+13
-28
lines changed

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/IdempotencyE2ET.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,4 @@ public void test_ttlNotExpired_sameResult_ttlExpired_differentResult() throws In
7676
Assertions.assertThat(result3.getResult()).isNotEqualTo(result2.getResult());
7777
}
7878

79-
@Test
80-
public void test_idempotencyWithRealDynamoDBTable() {
81-
// GIVEN
82-
String uniqueEvent = "{\"message\":\"test-" + UUID.randomUUID().toString() + "\"}";
83-
84-
// WHEN
85-
InvocationResult result1 = invokeFunction(functionName, uniqueEvent);
86-
InvocationResult result2 = invokeFunction(functionName, uniqueEvent);
87-
88-
// THEN
89-
Assertions.assertThat(result1.getResult()).isNotNull();
90-
Assertions.assertThat(result2.getResult()).isEqualTo(result1.getResult());
91-
}
9279
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
2222

23-
public class DynamoDBConfig {
23+
class DynamoDBConfig {
2424
protected static final String TABLE_NAME = "idempotency_table";
2525

2626
@Mock
2727
protected DynamoDbClient client;
2828

2929
@BeforeEach
30-
public void setupMocks() {
30+
void setupMocks() {
3131
MockitoAnnotations.openMocks(this);
3232
}
3333
}

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest;
2828
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse;
2929
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
30-
import software.amazon.awssdk.services.dynamodb.model.ResourceNotFoundException;
3130
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest;
3231
import software.amazon.lambda.powertools.idempotency.Constants;
3332
import software.amazon.lambda.powertools.idempotency.IdempotencyConfig;
@@ -37,7 +36,6 @@
3736

3837
import java.time.Instant;
3938
import java.time.temporal.ChronoUnit;
40-
import java.util.Collections;
4139
import java.util.HashMap;
4240
import java.util.Map;
4341

@@ -52,15 +50,15 @@
5250
/**
5351
* Unit tests for DynamoDBPersistenceStore using mocked DynamoDB client.
5452
*/
55-
public class DynamoDBPersistenceStoreTest {
53+
class DynamoDBPersistenceStoreTest {
5654
protected static final String TABLE_NAME = "idempotency_table";
5755
private DynamoDBPersistenceStore dynamoDBPersistenceStore;
5856

5957
@Mock
6058
private DynamoDbClient client;
6159

6260
@BeforeEach
63-
public void setup() {
61+
void setup() {
6462
MockitoAnnotations.openMocks(this);
6563
dynamoDBPersistenceStore = DynamoDBPersistenceStore.builder()
6664
.withTableName(TABLE_NAME)
@@ -71,7 +69,7 @@ public void setup() {
7169
// =================================================================
7270
//<editor-fold desc="putRecord">
7371
@Test
74-
public void putRecord_shouldCreateRecordInDynamoDB() throws IdempotencyItemAlreadyExistsException {
72+
void putRecord_shouldCreateRecordInDynamoDB() throws IdempotencyItemAlreadyExistsException {
7573
Instant now = Instant.now();
7674
long expiry = now.plus(3600, ChronoUnit.SECONDS).getEpochSecond();
7775

@@ -83,7 +81,7 @@ public void putRecord_shouldCreateRecordInDynamoDB() throws IdempotencyItemAlrea
8381
}
8482

8583
@Test
86-
public void putRecord_shouldThrowIdempotencyItemAlreadyExistsException_IfRecordAlreadyExist() {
84+
void putRecord_shouldThrowIdempotencyItemAlreadyExistsException_IfRecordAlreadyExist() {
8785
Instant now = Instant.now();
8886
long expiry = now.plus(3600, ChronoUnit.SECONDS).getEpochSecond();
8987

@@ -114,7 +112,7 @@ public void putRecord_shouldThrowIdempotencyItemAlreadyExistsException_IfRecordA
114112
//<editor-fold desc="getRecord">
115113

116114
@Test
117-
public void getRecord_shouldReturnExistingRecord() throws IdempotencyItemNotFoundException {
115+
void getRecord_shouldReturnExistingRecord() throws IdempotencyItemNotFoundException {
118116
Instant now = Instant.now();
119117
long expiry = now.plus(30, ChronoUnit.SECONDS).getEpochSecond();
120118

@@ -136,7 +134,7 @@ public void getRecord_shouldReturnExistingRecord() throws IdempotencyItemNotFoun
136134
}
137135

138136
@Test
139-
public void getRecord_shouldThrowException_whenRecordIsAbsent() {
137+
void getRecord_shouldThrowException_whenRecordIsAbsent() {
140138
GetItemResponse response = GetItemResponse.builder().build();
141139
when(client.getItem(any(GetItemRequest.class))).thenReturn(response);
142140

@@ -151,7 +149,7 @@ public void getRecord_shouldThrowException_whenRecordIsAbsent() {
151149
//<editor-fold desc="updateRecord">
152150

153151
@Test
154-
public void updateRecord_shouldUpdateRecord() {
152+
void updateRecord_shouldUpdateRecord() {
155153
Instant now = Instant.now();
156154
long expiry = now.plus(3600, ChronoUnit.SECONDS).getEpochSecond();
157155

@@ -173,7 +171,7 @@ public void updateRecord_shouldUpdateRecord() {
173171
//<editor-fold desc="deleteRecord">
174172

175173
@Test
176-
public void deleteRecord_shouldDeleteRecord() {
174+
void deleteRecord_shouldDeleteRecord() {
177175
when(client.deleteItem(any(DeleteItemRequest.class))).thenReturn(null);
178176

179177
dynamoDBPersistenceStore.deleteRecord("key");
@@ -186,7 +184,7 @@ public void deleteRecord_shouldDeleteRecord() {
186184

187185
@Test
188186
@SetEnvironmentVariable(key = Constants.IDEMPOTENCY_DISABLED_ENV, value = "true")
189-
public void idempotencyDisabled_noClientShouldBeCreated() {
187+
void idempotencyDisabled_noClientShouldBeCreated() {
190188
DynamoDBPersistenceStore store = DynamoDBPersistenceStore.builder().withTableName(TABLE_NAME).build();
191189
assertThatThrownBy(() -> store.getRecord("fake")).isInstanceOf(NullPointerException.class);
192190
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import java.util.HashMap;
4343
import java.util.Map;
4444

45-
public class IdempotencyTest {
45+
class IdempotencyTest {
4646

4747
@Mock
4848
private Context context;
@@ -56,7 +56,7 @@ void setUp() {
5656
}
5757

5858
@Test
59-
public void endToEndTest() {
59+
void endToEndTest() {
6060
// For this test, we'll simplify and just verify that the function works with mocks
6161
// The important part is that our new mocking approach doesn't break existing functionality
6262

0 commit comments

Comments
 (0)