Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Nov 20, 2017
1 parent 195d3d6 commit 2d1ec94
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 43 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/wildbit/java/postmark/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public TemplateValidation validateTemplate(TemplateToValidate data) throws Postm

public MessageResponse deliverMessage(TemplatedMessage data) throws PostmarkException, IOException {

/**
* Since template models can be complex, it is allowed that template model is a String or Object.
* If it's a String, we will auto convert it to Object.
/*
Since template models can be complex, it is allowed that template model is a String or Object.
If it's a String, we will auto convert it to Object.
*/
if (data.getTemplateModel().getClass() == String.class) {
data.setTemplateModel(dataHandler.fromJson(data.getTemplateModel().toString(),Object.class));
Expand Down Expand Up @@ -191,7 +191,7 @@ public OutboundMessageClicks getMessageClicks(String id, Parameters parameters)
}

/*
Inbound Messsages
Inbound Messages
*/

public InboundMessages getInboundMessages(Parameters parameters) throws PostmarkException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ protected String execute(HttpClient.REQUEST_TYPES request_type, String url) thro
* @param request_type HTTP request type
* @param url HTTP request URL
* @param data request data to send
* @return HTTP response message
* @throws PostmarkException Errors thrown by invalid or unhandled requests made to Postmark
* @throws IOException Errors thrown by Data Handler
*
* @see HttpClient for details about HTTP request execution.
* @return request response
* @return HTTP response message
*/
protected String execute(HttpClient.REQUEST_TYPES request_type, String url, Object data) throws PostmarkException, IOException {
HttpClient.ClientResponse response = httpClient.execute(request_type, getSecureUrl(url), dataHandler.toJson(data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String toString() {

for (HashMap.Entry<String, String> entry : parameters.entrySet()) {
parameterString += addParameters(parameterString, entry.getKey() + "=" + entry.getValue());
};
}

return parameterString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.databind.*;

import java.io.IOException;
import java.util.ArrayList;

/**
* This class represents data handler between API client and HTTP client.
Expand Down Expand Up @@ -72,8 +71,8 @@ public String formatErrorMessage(String data) throws IOException {
}

/**
* Sets data mapper to be strict when making conversion of data to POJO objects.
* If there is a mismatch between POJO object and String in any other case than letter case,
* Sets data mapper to be strict when making conversion of data to objects.
* If there is a mismatch between object and String in any other case than letter case,
* exception will be thrown.
*/
public void setStrictMapper() {
Expand All @@ -84,7 +83,7 @@ public void setStrictMapper() {
}

/**
* Sets data mapper to be very liberal when making conversion of data to POJO objects.
* Sets data mapper to be very liberal when making conversion of data to objects.
* Most of the time exception will NOT be thrown.
*/
public void setLiberalMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ public void setHeaders(ArrayList<Header> headers) {

public void addHeader(String name, String value) {
if (this.headers == null) {
setHeaders(new ArrayList<Header>());
setHeaders(new ArrayList<>());
}
this.headers.add(new Header(name,value));
}

public void clearHeaders() {
if (this.headers == null) {
if (this.headers != null) {
this.headers.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.wildbit.java.postmark.client.data.model.message;
import java.util.Date;

/**
* HTTP send request response object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Date;

/**
* Parrent stats class - object. Contains attributes each stat contains.
* Parent stats class - object. Contains attributes each stat contains.
*/
public class BaseStat {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ public void setHeaders(ArrayList<Header> headers) {

public void addHeader(String name, String value) {
if (this.headers == null) {
setHeaders(new ArrayList<Header>());
setHeaders(new ArrayList<>());
}
this.headers.add(new Header(name,value));
}

public void clearHeaders() {
if (this.headers == null) {
if (this.headers != null) {
this.headers.clear();
}
}
Expand Down Expand Up @@ -211,16 +211,16 @@ private String readFileContentType(String path) {
*/
private String convertRecipients(HashMap<String,String> recipients) {

String recipientsString = "";
StringBuilder recipientsString = new StringBuilder();

Iterator<HashMap.Entry<String, String>> entries = recipients.entrySet().iterator();
while (entries.hasNext()) {
HashMap.Entry<String, String> entry = entries.next();
recipientsString += "\"" + entry.getKey() + "\"" + "<" + entry.getValue() + ">";
if (entries.hasNext()) { recipientsString += ","; }
recipientsString.append("\"").append(entry.getKey()).append("\"").append("<").append(entry.getValue()).append(">");
if (entries.hasNext()) { recipientsString.append(","); }
}

return recipientsString;
return recipientsString.toString();
}

}
2 changes: 1 addition & 1 deletion src/main/resources/.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version: ${postmark.version}
Version= ${postmark.version}
6 changes: 1 addition & 5 deletions src/test/java/MessageTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.wildbit.java.postmark.Postmark;
import com.wildbit.java.postmark.client.ApiClient;
import com.wildbit.java.postmark.client.data.DataHandler;
import com.wildbit.java.postmark.client.data.model.message.Message;
import com.wildbit.java.postmark.client.data.model.message.MessageResponse;
import com.wildbit.java.postmark.client.exception.InvalidMessageException;
Expand Down Expand Up @@ -31,10 +30,7 @@ void send() throws PostmarkException, IOException {
void invalidMessagetoSend() throws PostmarkException, IOException {
Message message = new Message("[email protected]", null, "Hello from Postmark!", "Hello body");

Throwable exception = assertThrows(InvalidMessageException.class, () -> {
client.deliverMessage(message);
});

Throwable exception = assertThrows(InvalidMessageException.class, () -> client.deliverMessage(message));
assertEquals("Zero recipients specified", exception.getMessage());
}
}
1 change: 0 additions & 1 deletion src/test/java/MessagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down
1 change: 0 additions & 1 deletion src/test/java/PostmarkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Map;


import static org.junit.jupiter.api.Assertions.*;
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/client/HttpClientTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package client;

import com.wildbit.java.postmark.client.BaseApiClient;
import com.wildbit.java.postmark.client.HttpClient;
import com.wildbit.java.postmark.client.HttpClientHandler;
import com.wildbit.java.postmark.client.exception.PostmarkException;
import org.junit.jupiter.api.Test;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.util.*;

Expand Down
7 changes: 3 additions & 4 deletions src/test/java/client/data/DataHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ HashMap<String, String> getHashMap() {
}

String getStringHashMap() {
String stringHashMap = "{\n" +

return "{\n" +
" \"Key2\" : \"Value2\",\n" +
" \"Key1\" : \"Value1\"\n" +
"}";

return stringHashMap;
}

@Test
Expand All @@ -45,7 +44,7 @@ void liberalMapper() throws IOException {
@Test
void strictMapper() throws IOException {
Throwable exception = assertThrows(UnrecognizedPropertyException.class,
()->{dataHandler.fromJson(getStringHashMap(), BaseMessageResponse.class);} );
()-> dataHandler.fromJson(getStringHashMap(), BaseMessageResponse.class));

}

Expand Down
4 changes: 0 additions & 4 deletions src/test/java/data/MessageTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package data;


import com.wildbit.java.postmark.Postmark;
import com.wildbit.java.postmark.client.ApiClient;
import com.wildbit.java.postmark.client.data.DataHandler;
import com.wildbit.java.postmark.client.data.model.message.Message;
import org.junit.jupiter.api.Test;

import javax.ws.rs.core.MultivaluedHashMap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down

0 comments on commit 2d1ec94

Please sign in to comment.