Skip to content

Commit

Permalink
PB-26352. Cleanup Code
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 24, 2019
1 parent 8861312 commit fe94b35
Show file tree
Hide file tree
Showing 59 changed files with 761 additions and 805 deletions.
4 changes: 1 addition & 3 deletions sdk/src/main/java/com/silanis/esl/api/util/JacksonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ public static Map<String,Object> merge(Map<String,Object> baseMap, Map<String,Ob
if ( baseMap.containsKey(key) ) {
// Concat the delta list onto the base list
List<Object> resultList = (List<Object>) resultMap.get(key);
for ( Object object : (List<Object>)value ) {
resultList.add(object);
}
resultList.addAll((List<Object>) value);
} else {
resultMap.put(key, value);
}
Expand Down
30 changes: 16 additions & 14 deletions sdk/src/main/java/com/silanis/esl/sdk/internal/Support.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.silanis.esl.sdk.internal;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpUriRequest;

import java.util.logging.Level;
import java.util.logging.Logger;

public class Support {

private static Logger LOG = Logger.getLogger(Support.class.getName());
Expand All @@ -15,30 +16,31 @@ public void log(HttpUriRequest request) {
}

private String formatHeaders(Header[] allHeaders) {
if(allHeaders != null){
String formattedHeaders = "{";
if (allHeaders != null) {
StringBuilder formattedHeaders = new StringBuilder("{");
for (Header allHeader : allHeaders) {
formattedHeaders += "[";
formattedHeaders.append("[");
final String name = allHeader.getName();
if(name != null){
formattedHeaders += name;
if (name != null) {
formattedHeaders.append(name);
}
formattedHeaders += "=";
formattedHeaders.append("=");
final String value = allHeader.getValue();
if(value != null){
formattedHeaders += value;
if (value != null) {
formattedHeaders.append(value);
}
formattedHeaders += "]";
formattedHeaders.append("]");
}
formattedHeaders += "}";
return formattedHeaders;
formattedHeaders.append("}");
return formattedHeaders.toString();
}
return "";
}

public void logRequest(String httpVerb, String path, String jsonPayload) {
LOG.log(Level.FINE, "{0} on {1}\n {2}", new Object[]{httpVerb, path, jsonPayload});
}

public void logRequest(String httpVerb, String path) {
LOG.log(Level.FINE, "{0} on {1}", new Object[]{httpVerb, path});
}
Expand All @@ -47,7 +49,7 @@ public void logResponse(String response) {
LOG.fine("RESPONSE: \n" + response);
}

public void logError( com.silanis.esl.api.model.Error errorMessage){
public void logError(com.silanis.esl.api.model.Error errorMessage) {
LOG.severe("message:" + errorMessage.getMessage() + ", http code:" + errorMessage.getCode());
}

Expand Down
10 changes: 5 additions & 5 deletions sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,23 @@ public UrlTemplate addParam(String paramKey, String paramValue) {
}

public String build() {
String url = baseUrl + path;
StringBuilder url = new StringBuilder(baseUrl + path);

boolean isFirstParam = true;
for (Map.Entry<String, String> param : params.entrySet()) {
final String paramValue = param.getValue();
if (isNotBlank(paramValue)) {
if (isFirstParam) {
url += "?";
url.append("?");
isFirstParam = false;
} else {
url += "&";
url.append("&");
}
url += param.getKey() + "=" + paramValue;
url.append(param.getKey()).append("=").append(paramValue);
}
}

return url;
return url.toString();
}

}
63 changes: 31 additions & 32 deletions sdk/src/test/java/com/silanis/esl/sdk/AuthenticationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,90 @@
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.Is.is;

public class AuthenticationTest {
@Test
public void constructorWithMethod() {
for ( AuthenticationMethod authenticationMethod : AuthenticationMethod.values() ) {
Authentication authentication = new Authentication( authenticationMethod );
assertThat( "method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is( equalTo( authenticationMethod ) ) );
for (AuthenticationMethod authenticationMethod : AuthenticationMethod.values()) {
Authentication authentication = new Authentication(authenticationMethod);
assertThat("method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is(authenticationMethod));
}
}

private List<Challenge> challenges;

private Authentication newChallengeAuthentication() {
challenges = new ArrayList<Challenge>();
challenges.add( new Challenge( "one", "two" ) );
challenges.add( new Challenge( "three", "four" ) );
challenges.add( new Challenge( "four", "five" ) );
return new Authentication( challenges );
challenges.add(new Challenge("one", "two"));
challenges.add(new Challenge("three", "four"));
challenges.add(new Challenge("four", "five"));
return new Authentication(challenges);
}

@Test
public void constructorWithListOfChallenges() {
Authentication authentication = newChallengeAuthentication();

assertThat( "method not set correctly", authentication.getMethod(), is( equalTo( AuthenticationMethod.CHALLENGE ) ) );
assertThat( "challenges list is null", authentication.getChallenges(), is( notNullValue() ) );
assertThat( "challenges list is wrong size", authentication.getChallenges().size(), is( equalTo( challenges.size() ) ) );
for ( int i = 0; i < challenges.size(); i++ ) {
assertThat( "challenge question #" + i + " is not set correctly", authentication.getChallenges().get( i ).getQuestion(), is( equalTo( challenges.get( i ).getQuestion() ) ) );
assertThat( "challenge answer #" + i + " is not set correctly", authentication.getChallenges().get( i ).getAnswer(), is( equalTo( challenges.get( i ).getAnswer() ) ) );
assertThat("method not set correctly", authentication.getMethod(), is(AuthenticationMethod.CHALLENGE));
assertThat("challenges list is null", authentication.getChallenges(), notNullValue());
assertThat("challenges list is wrong size", authentication.getChallenges().size(), is(challenges.size()));
for (int i = 0; i < challenges.size(); i++) {
assertThat("challenge question #" + i + " is not set correctly", authentication.getChallenges().get(i).getQuestion(), is(challenges.get(i).getQuestion()));
assertThat("challenge answer #" + i + " is not set correctly", authentication.getChallenges().get(i).getAnswer(), is(challenges.get(i).getAnswer()));
}
}

private String phoneNumber;

public Authentication newSMSAuthentication() {
phoneNumber = "1234567890";
return new Authentication( phoneNumber );
return new Authentication(phoneNumber);
}

@Test
public void constructorWithTelephoneNumber() {
Authentication authentication = newSMSAuthentication();

assertThat( "authentication method is not being set to sms", authentication.getMethod(), is( equalTo( AuthenticationMethod.SMS ) ) );
assertThat( "phone number is not set correctly", authentication.getPhoneNumber(), is( equalTo( phoneNumber ) ) );
assertThat("authentication method is not being set to sms", authentication.getMethod(), is(AuthenticationMethod.SMS));
assertThat("phone number is not set correctly", authentication.getPhoneNumber(), is(phoneNumber));
}

private Authentication newEmailAuthentication() {
return new Authentication( AuthenticationMethod.EMAIL );
return new Authentication(AuthenticationMethod.EMAIL);
}

@Test
public void emailAuthToAPIAuth() {
Authentication authentication = newEmailAuthentication();
Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication();
assertThat("Null value was returned by converter", auth, is(notNullValue()));
assertThat( "AuthScheme was not set to NONE", auth.getScheme(), is( equalTo( "NONE" ) ) );
assertThat("Null value was returned by converter", auth, notNullValue());
assertThat("AuthScheme was not set to NONE", auth.getScheme(), is("NONE"));
}

@Test
public void challengeAuthToAPIAuth() {
Authentication authentication = newChallengeAuthentication();
Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication();
assertThat("Null value was returned by converter", auth, is(notNullValue()));
assertThat( "AuthScheme was not set to CHALLENGE", auth.getScheme(), is( equalTo( "CHALLENGE" ) ) );
assertThat( "Challenge list was set to null", auth.getChallenges(), is( notNullValue() ) );
assertThat( "Challenge list did not contain the expected number of elements", auth.getChallenges().size(), is( equalTo( challenges.size() ) ) );
for ( int i = 0; i < challenges.size(); i++ ) {
assertThat( "Challenge question #" + i + " + was not set correctly", auth.getChallenges().get( i ).getQuestion(), is( equalTo( challenges.get( i ).getQuestion() ) ) );
assertThat( "Challenge answer #" + i + " + was not set correctly", auth.getChallenges().get( i ).getAnswer(), is( equalTo( challenges.get( i ).getAnswer() ) ) );
assertThat("Null value was returned by converter", auth, notNullValue());
assertThat("AuthScheme was not set to CHALLENGE", auth.getScheme(), is("CHALLENGE"));
assertThat("Challenge list was set to null", auth.getChallenges(), notNullValue());
assertThat("Challenge list did not contain the expected number of elements", auth.getChallenges().size(), is(challenges.size()));
for (int i = 0; i < challenges.size(); i++) {
assertThat("Challenge question #" + i + " + was not set correctly", auth.getChallenges().get(i).getQuestion(), is(challenges.get(i).getQuestion()));
assertThat("Challenge answer #" + i + " + was not set correctly", auth.getChallenges().get(i).getAnswer(), is(challenges.get(i).getAnswer()));
}
}

@Test
public void smsAuthToAPIAuth() {
Authentication authentication = newSMSAuthentication();
Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication();
assertThat("AuthScheme was not set to SMS", auth.getScheme(), is(equalTo("SMS")));
assertThat( "Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue() );
assertThat( "Challenges list was not length 1", auth.getChallenges().size(), is( equalTo( 1 ) ) );
assertThat( "First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get( 0 ).getQuestion(), is( equalTo( phoneNumber ) ) );
assertThat( "First challenge answer should be blank", auth.getChallenges().get( 0 ).getAnswer(), is( notNullValue() ) );
assertThat("AuthScheme was not set to SMS", auth.getScheme(), is("SMS"));
assertThat("Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue());
assertThat("Challenges list was not length 1", auth.getChallenges().size(), is(1));
assertThat("First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get(0).getQuestion(), is(phoneNumber));
assertThat("First challenge answer should be blank", auth.getChallenges().get(0).getAnswer(), notNullValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void toAPILayoutOptions() {
settings.setShowGlobalConfirmButton( true );
settings.setShowGlobalDownloadButton( true );
settings.setShowGlobalSaveAsLayoutButton( true );
LayoutOptions layoutOptions = layoutOptions = new CeremonyLayoutSettingsConverter(settings).toAPILayoutOptions();
LayoutOptions layoutOptions = new CeremonyLayoutSettingsConverter(settings).toAPILayoutOptions();
assertThat( "", layoutOptions.getBrandingBar().getLogo().getLink(), is( equalTo( settings.getLogoImageLink() ) ) );
}

Expand Down
7 changes: 3 additions & 4 deletions sdk/src/test/java/com/silanis/esl/sdk/DocumentTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class DocumentTypeTest {

@Test
public void normalizingNameReplacesWhitespaceWithUnderscores() {
assertThat(DocumentType.PDF.normalizeName("Some File.pdf"), is(equalTo("Some_File.pdf")));
assertThat(DocumentType.PDF.normalizeName("Some File.pdf"), is("Some_File.pdf"));
}

@Test
public void appendsExtensionWhenNoneIsFound() {
assertThat(DocumentType.PDF.normalizeName("Some File"), is(equalTo("Some_File.pdf")));
assertThat(DocumentType.PDF.normalizeName("Some File"), is("Some_File.pdf"));
}

@Test
public void doesNotAppendExtraDotWhenOneIsFoundAtNameEnd() {
assertThat(DocumentType.WORD.normalizeName("Some File."), is(equalTo("Some_File.docx")));
assertThat(DocumentType.WORD.normalizeName("Some File."), is("Some_File.docx"));
}
}
2 changes: 1 addition & 1 deletion sdk/src/test/java/com/silanis/esl/sdk/SenderInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testToAPI() {

Sender sender = new SenderConverter(senderInfo).toAPISender();

assertThat("first name was not properly set or retrieved", sender.getFirstName(), is(equalTo("firstName")));
assertThat("first name was not properly set or retrieved", sender.getFirstName(), is("firstName"));
assertThat( "last name was not properly set or retrieved", sender.getLastName(), is( equalTo( "lastName" ) ) );
assertThat( "company was not properly set or retrieved", sender.getCompany(), is( equalTo( "company" ) ) );
assertThat( "title was not properly set or retrieved", sender.getTitle(), is( equalTo( "title" ) ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.Test;

import static com.silanis.esl.sdk.builder.AttachmentRequirementBuilder.newAttachmentRequirementWithName;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Expand All @@ -25,8 +24,8 @@ public void buildWithSpecificValues() {
.isRequiredAttachment()
.build();

assertThat("Attachment's name was not set correctly.", attachmentRequirement.getName(), is(equalTo(name)));
assertThat("Attachment's description was not set correctly.", attachmentRequirement.getDescription(), is(equalTo(description)));
assertThat("Attachment's name was not set correctly.", attachmentRequirement.getName(), is(name));
assertThat("Attachment's description was not set correctly.", attachmentRequirement.getDescription(), is(description));
assertThat("Attachment's required property was not set correctly", attachmentRequirement.isRequired(), is(isRequired));
}

Expand Down
Loading

0 comments on commit fe94b35

Please sign in to comment.