Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use List interface instead of ArrayList for return types and method parameters #41

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/com/wildbit/java/postmark/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* Class that handles on very top level all API requests. All Postmark public endpoints which
Expand Down Expand Up @@ -68,9 +68,9 @@ public MessageResponse deliverMessage(Message data) throws PostmarkException, IO
return dataHandler.fromJson(response, MessageResponse.class);
}

public ArrayList<MessageResponse> deliverMessage(ArrayList<Message> data) throws PostmarkException, IOException {
public List<MessageResponse> deliverMessage(List<Message> data) throws PostmarkException, IOException {
String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(sendingEndpoint + "batch"), data);
return dataHandler.fromJson(response, new TypeReference<ArrayList<MessageResponse>>() {});
return dataHandler.fromJson(response, new TypeReference<List<MessageResponse>>() {});
}

/*
Expand Down Expand Up @@ -168,19 +168,19 @@ public MessageResponse deliverMessageWithTemplate(TemplatedMessage data) throws
return dataHandler.fromJson(response, MessageResponse.class);
}

public ArrayList<MessageResponse> deliverMessageWithTemplate(ArrayList<TemplatedMessage> data) throws PostmarkException, IOException {
public List<MessageResponse> deliverMessageWithTemplate(List<TemplatedMessage> data) throws PostmarkException, IOException {
/*
When sending array of emails with templates, additional top level field is used called "Messages".
This introduces unnecessary difference between batch and batchWithTemplates endpoint in data model.
To keep it simple, this additional level is added before executing batch send.
*/
HashMap<String, ArrayList> dataToSend = new HashMap<>();
HashMap<String, List> dataToSend = new HashMap<>();
dataToSend.put("Messages", data);

for(TemplatedMessage templateMessage:data) { setTemplateModelToObject(templateMessage); }

String response = execute(HttpClient.REQUEST_TYPES.POST, getEndpointUrl(sendingEndpoint + "batchWithTemplates"), dataToSend);
return dataHandler.fromJson(response, new TypeReference<ArrayList<MessageResponse>>() {});
return dataHandler.fromJson(response, new TypeReference<List<MessageResponse>>() {});
}

private void setTemplateModelToObject(TemplatedMessage data) throws IOException {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/unit/data/BounceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -37,7 +38,7 @@ void bouncesData() throws IOException{
Bounce bounce = new Bounce();
bounce.setId(1L);
bounce.setContent("test");
ArrayList<Bounce> data = new ArrayList<>();
List<Bounce> data = new ArrayList<>();
data.add(bounce);

Bounces bounces = new Bounces();
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/unit/data/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -85,7 +86,7 @@ void singleMessageFromRecipientFullName() {
void singleMessageToRecipient() {
Message message = new Message();

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add("[email protected]");

message.setTo(recipients);
Expand All @@ -97,7 +98,7 @@ void simpleMessageToRecipients() throws IOException {

Message message = new Message();

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add("[email protected]");
recipients.add("[email protected]");
recipients.add("[email protected]");
Expand Down Expand Up @@ -126,7 +127,7 @@ void simpleMessageCcRecipients() throws IOException {

Message message = new Message();

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add("[email protected]");
recipients.add("[email protected]");
recipients.add("[email protected]");
Expand Down Expand Up @@ -155,7 +156,7 @@ void simpleMessageBccRecipients() throws IOException {

Message message = new Message();

ArrayList<String> recipients = new ArrayList<>();
List<String> recipients = new ArrayList<>();
recipients.add("[email protected]");
recipients.add("[email protected]");
recipients.add("[email protected]");
Expand Down