Skip to content

Commit 27d1fc0

Browse files
committed
rename methods in deserializer
1 parent c5e04d9 commit 27d1fc0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

powertools-serialization/src/main/java/software/amazon/lambda/powertools/utilities/EventDeserializer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class EventDeserializer {
3030

3131
private static final Logger LOG = LoggerFactory.getLogger(EventDeserializer.class);
3232

33-
public static EventPart from(Object obj) {
33+
public static EventPart extractDataFrom(Object obj) {
3434
if (obj instanceof String) {
3535
return new EventPart((String) obj);
3636
} else if (obj instanceof Map) {
@@ -110,7 +110,7 @@ public EventPart(Object content) {
110110
this.contentObject = content;
111111
}
112112

113-
public <T> T extractDataAs(Class<T> clazz) {
113+
public <T> T as(Class<T> clazz) {
114114
try {
115115
if (content != null) {
116116
if (content.getClass().equals(clazz)) {
@@ -134,7 +134,7 @@ public <T> T extractDataAs(Class<T> clazz) {
134134
}
135135
}
136136

137-
public <T> List<T> extractDataAsListOf(Class<T> clazz) {
137+
public <T> List<T> asListOf(Class<T> clazz) {
138138
if (contentList == null) {
139139
throw new EventDeserializationException("Event content is null");
140140
}

powertools-serialization/src/test/java/software/amazon/lambda/powertools/utilities/EventDeserializerTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626

2727
import static org.assertj.core.api.Assertions.assertThat;
2828
import static org.assertj.core.api.Assertions.assertThatThrownBy;
29-
import static software.amazon.lambda.powertools.utilities.EventDeserializer.from;
29+
import static software.amazon.lambda.powertools.utilities.EventDeserializer.extractDataFrom;
3030

3131
public class EventDeserializerTest {
3232

3333
@Test
3434
public void testDeserializeStringAsString_shouldReturnString() {
3535
String stringEvent = "Hello World";
36-
String result = from(stringEvent).extractDataAs(String.class);
36+
String result = extractDataFrom(stringEvent).as(String.class);
3737
assertThat(result).isEqualTo(stringEvent);
3838
}
3939

4040
@Test
4141
public void testDeserializeStringAsObject_shouldReturnObject() {
4242
String productStr = "{\"id\":1234, \"name\":\"product\", \"price\":42}";
43-
Product product = from(productStr).extractDataAs(Product.class);
43+
Product product = extractDataFrom(productStr).as(Product.class);
4444
assertProduct(product);
4545
}
4646

@@ -50,68 +50,68 @@ public void testDeserializeMapAsObject_shouldReturnObject() {
5050
map.put("id", 1234);
5151
map.put("name", "product");
5252
map.put("price", 42);
53-
Product product = from(map).extractDataAs(Product.class);
53+
Product product = extractDataFrom(map).as(Product.class);
5454
assertProduct(product);
5555
}
5656

5757
@ParameterizedTest
5858
@Event(value = "apigw_event.json", type = APIGatewayProxyRequestEvent.class)
5959
public void testDeserializeAPIGWEventBodyAsObject_shouldReturnObject(APIGatewayProxyRequestEvent event) {
60-
Product product = from(event).extractDataAs(Product.class);
60+
Product product = extractDataFrom(event).as(Product.class);
6161
assertProduct(product);
6262
}
6363

6464
@ParameterizedTest
6565
@Event(value = "apigw_event.json", type = APIGatewayProxyRequestEvent.class)
6666
public void testDeserializeAPIGWEventBodyAsWrongObjectType_shouldThrowException(APIGatewayProxyRequestEvent event) {
67-
assertThatThrownBy(() -> from(event).extractDataAs(Basket.class))
67+
assertThatThrownBy(() -> extractDataFrom(event).as(Basket.class))
6868
.isInstanceOf(EventDeserializationException.class)
6969
.hasMessage("Cannot load the event as Basket");
7070
}
7171

7272
@ParameterizedTest
7373
@Event(value = "sns_event.json", type = SNSEvent.class)
7474
public void testDeserializeSNSEventMessageAsObject_shouldReturnObject(SNSEvent event) {
75-
Product product = from(event).extractDataAs(Product.class);
75+
Product product = extractDataFrom(event).as(Product.class);
7676
assertProduct(product);
7777
}
7878

7979
@ParameterizedTest
8080
@Event(value = "sqs_event.json", type = SQSEvent.class)
8181
public void testDeserializeSQSEventMessageAsList_shouldReturnList(SQSEvent event) {
82-
List<Product> products = from(event).extractDataAsListOf(Product.class);
82+
List<Product> products = extractDataFrom(event).asListOf(Product.class);
8383
assertThat(products).hasSize(2);
8484
assertProduct(products.get(0));
8585
}
8686

8787
@ParameterizedTest
8888
@Event(value = "kinesis_event.json", type = KinesisEvent.class)
8989
public void testDeserializeKinesisEventMessageAsList_shouldReturnList(KinesisEvent event) {
90-
List<Product> products = from(event).extractDataAsListOf(Product.class);
90+
List<Product> products = extractDataFrom(event).asListOf(Product.class);
9191
assertThat(products).hasSize(2);
9292
assertProduct(products.get(0));
9393
}
9494

9595
@ParameterizedTest
9696
@Event(value = "kafka_event.json", type = KafkaEvent.class)
9797
public void testDeserializeKafkaEventMessageAsList_shouldReturnList(KafkaEvent event) {
98-
List<Product> products = from(event).extractDataAsListOf(Product.class);
98+
List<Product> products = extractDataFrom(event).asListOf(Product.class);
9999
assertThat(products).hasSize(2);
100100
assertProduct(products.get(0));
101101
}
102102

103103
@ParameterizedTest
104104
@Event(value = "sqs_event.json", type = SQSEvent.class)
105105
public void testDeserializeSQSEventMessageAsObject_shouldThrowException(SQSEvent event) {
106-
assertThatThrownBy(() -> from(event).extractDataAs(Product.class))
106+
assertThatThrownBy(() -> extractDataFrom(event).as(Product.class))
107107
.isInstanceOf(EventDeserializationException.class)
108108
.hasMessageContaining("consider using 'extractDataAsListOf' instead");
109109
}
110110

111111
@Test
112112
public void testDeserializeProductAsProduct_shouldReturnProduct() {
113113
Product myProduct = new Product(1234, "product", 42);
114-
Product product = from(myProduct).extractDataAs(Product.class);
114+
Product product = extractDataFrom(myProduct).as(Product.class);
115115
assertProduct(product);
116116
}
117117

0 commit comments

Comments
 (0)