Skip to content

Commit 26e2ff7

Browse files
authored
Merge pull request #311 from carlzogh/master
Assert on AttributeValue List type to ensure consistency when empty and non-empty
2 parents 3583ff5 + f340175 commit 26e2ff7

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/v1/dynamodb/DynamodbAttributeValueTransformerTest.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public void testToAttributeValueV1_L() {
179179
com.amazonaws.services.dynamodbv2.model.AttributeValue convertedAttributeValueL =
180180
DynamodbAttributeValueTransformer.toAttributeValueV1(attributeValueL_event);
181181
Assertions.assertEquals(attributeValueL_v1, convertedAttributeValueL);
182+
Assertions.assertEquals("ArrayList", convertedAttributeValueL.getL().getClass().getSimpleName(), "List is mutable");
182183
}
183184

184185
@Test
@@ -262,12 +263,14 @@ public void testToAttributeValueV1_DoesNotThrowWhenEmpty_BS() {
262263

263264
@Test
264265
public void testToAttributeValueV1_DoesNotThrowWhenEmpty_L() {
265-
Assertions.assertDoesNotThrow(() ->
266-
DynamodbAttributeValueTransformer.toAttributeValueV1(new AttributeValue().withL())
267-
);
268-
Assertions.assertDoesNotThrow(() ->
269-
DynamodbAttributeValueTransformer.toAttributeValueV1(new AttributeValue().withL(Collections.emptyList()))
270-
);
266+
Assertions.assertDoesNotThrow(() -> {
267+
com.amazonaws.services.dynamodbv2.model.AttributeValue attributeValue = DynamodbAttributeValueTransformer.toAttributeValueV1(new AttributeValue().withL());
268+
Assertions.assertEquals("ArrayList", attributeValue.getL().getClass().getSimpleName(), "List is mutable");
269+
});
270+
Assertions.assertDoesNotThrow(() -> {
271+
com.amazonaws.services.dynamodbv2.model.AttributeValue attributeValue = DynamodbAttributeValueTransformer.toAttributeValueV1(new AttributeValue().withL(Collections.emptyList()));
272+
Assertions.assertEquals("ArrayList", attributeValue.getL().getClass().getSimpleName(), "List is mutable");
273+
});
271274
}
272275

273276
@Test

aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/v2/dynamodb/DynamodbAttributeValueTransformerTest.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void testToAttributeValueV2_L() {
183183
software.amazon.awssdk.services.dynamodb.model.AttributeValue convertedAttributeValueL =
184184
DynamodbAttributeValueTransformer.toAttributeValueV2(attributeValueL_event);
185185
Assertions.assertEquals(attributeValueL_v2, convertedAttributeValueL);
186+
Assertions.assertEquals("UnmodifiableRandomAccessList", convertedAttributeValueL.l().getClass().getSimpleName(), "List is immutable");
186187
}
187188

188189
@Test
@@ -266,12 +267,14 @@ public void testToAttributeValueV2_DoesNotThrowWhenEmpty_BS() {
266267

267268
@Test
268269
public void testToAttributeValueV2_DoesNotThrowWhenEmpty_L() {
269-
Assertions.assertDoesNotThrow(() ->
270-
DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL())
271-
);
272-
Assertions.assertDoesNotThrow(() ->
273-
DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL(Collections.emptyList()))
274-
);
270+
Assertions.assertDoesNotThrow(() -> {
271+
software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValue = DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL());
272+
Assertions.assertEquals("UnmodifiableRandomAccessList", attributeValue.l().getClass().getSimpleName(), "List is immutable");
273+
});
274+
Assertions.assertDoesNotThrow(() -> {
275+
software.amazon.awssdk.services.dynamodb.model.AttributeValue attributeValue = DynamodbAttributeValueTransformer.toAttributeValueV2(new AttributeValue().withL(Collections.emptyList()));
276+
Assertions.assertEquals("UnmodifiableRandomAccessList", attributeValue.l().getClass().getSimpleName(), "List is immutable");
277+
});
275278
}
276279

277280
@Test

0 commit comments

Comments
 (0)