Skip to content

Commit 26260b1

Browse files
author
john
committed
PB-26352. Cleanup Code
1 parent 7801063 commit 26260b1

59 files changed

Lines changed: 761 additions & 805 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sdk/src/main/java/com/silanis/esl/api/util/JacksonUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ public static Map<String,Object> merge(Map<String,Object> baseMap, Map<String,Ob
146146
if ( baseMap.containsKey(key) ) {
147147
// Concat the delta list onto the base list
148148
List<Object> resultList = (List<Object>) resultMap.get(key);
149-
for ( Object object : (List<Object>)value ) {
150-
resultList.add(object);
151-
}
149+
resultList.addAll((List<Object>) value);
152150
} else {
153151
resultMap.put(key, value);
154152
}

sdk/src/main/java/com/silanis/esl/sdk/internal/Support.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.silanis.esl.sdk.internal;
22

3-
import java.util.logging.Level;
4-
import java.util.logging.Logger;
53
import org.apache.http.Header;
64
import org.apache.http.client.methods.HttpUriRequest;
75

6+
import java.util.logging.Level;
7+
import java.util.logging.Logger;
8+
89
public class Support {
910

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

1718
private String formatHeaders(Header[] allHeaders) {
18-
if(allHeaders != null){
19-
String formattedHeaders = "{";
19+
if (allHeaders != null) {
20+
StringBuilder formattedHeaders = new StringBuilder("{");
2021
for (Header allHeader : allHeaders) {
21-
formattedHeaders += "[";
22+
formattedHeaders.append("[");
2223
final String name = allHeader.getName();
23-
if(name != null){
24-
formattedHeaders += name;
24+
if (name != null) {
25+
formattedHeaders.append(name);
2526
}
26-
formattedHeaders += "=";
27+
formattedHeaders.append("=");
2728
final String value = allHeader.getValue();
28-
if(value != null){
29-
formattedHeaders += value;
29+
if (value != null) {
30+
formattedHeaders.append(value);
3031
}
31-
formattedHeaders += "]";
32+
formattedHeaders.append("]");
3233
}
33-
formattedHeaders += "}";
34-
return formattedHeaders;
34+
formattedHeaders.append("}");
35+
return formattedHeaders.toString();
3536
}
3637
return "";
3738
}
3839

3940
public void logRequest(String httpVerb, String path, String jsonPayload) {
4041
LOG.log(Level.FINE, "{0} on {1}\n {2}", new Object[]{httpVerb, path, jsonPayload});
4142
}
43+
4244
public void logRequest(String httpVerb, String path) {
4345
LOG.log(Level.FINE, "{0} on {1}", new Object[]{httpVerb, path});
4446
}
@@ -47,7 +49,7 @@ public void logResponse(String response) {
4749
LOG.fine("RESPONSE: \n" + response);
4850
}
4951

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

sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,23 @@ public UrlTemplate addParam(String paramKey, String paramValue) {
179179
}
180180

181181
public String build() {
182-
String url = baseUrl + path;
182+
StringBuilder url = new StringBuilder(baseUrl + path);
183183

184184
boolean isFirstParam = true;
185185
for (Map.Entry<String, String> param : params.entrySet()) {
186186
final String paramValue = param.getValue();
187187
if (isNotBlank(paramValue)) {
188188
if (isFirstParam) {
189-
url += "?";
189+
url.append("?");
190190
isFirstParam = false;
191191
} else {
192-
url += "&";
192+
url.append("&");
193193
}
194-
url += param.getKey() + "=" + paramValue;
194+
url.append(param.getKey()).append("=").append(paramValue);
195195
}
196196
}
197197

198-
return url;
198+
return url.toString();
199199
}
200200

201201
}

sdk/src/test/java/com/silanis/esl/sdk/AuthenticationTest.java

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,91 +8,90 @@
88
import java.util.List;
99

1010
import static org.hamcrest.MatcherAssert.assertThat;
11-
import static org.hamcrest.Matchers.equalTo;
1211
import static org.hamcrest.Matchers.notNullValue;
1312
import static org.hamcrest.core.Is.is;
1413

1514
public class AuthenticationTest {
1615
@Test
1716
public void constructorWithMethod() {
18-
for ( AuthenticationMethod authenticationMethod : AuthenticationMethod.values() ) {
19-
Authentication authentication = new Authentication( authenticationMethod );
20-
assertThat( "method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is( equalTo( authenticationMethod ) ) );
17+
for (AuthenticationMethod authenticationMethod : AuthenticationMethod.values()) {
18+
Authentication authentication = new Authentication(authenticationMethod);
19+
assertThat("method is not set correctly for " + authenticationMethod.name(), authentication.getMethod(), is(authenticationMethod));
2120
}
2221
}
2322

2423
private List<Challenge> challenges;
2524

2625
private Authentication newChallengeAuthentication() {
2726
challenges = new ArrayList<Challenge>();
28-
challenges.add( new Challenge( "one", "two" ) );
29-
challenges.add( new Challenge( "three", "four" ) );
30-
challenges.add( new Challenge( "four", "five" ) );
31-
return new Authentication( challenges );
27+
challenges.add(new Challenge("one", "two"));
28+
challenges.add(new Challenge("three", "four"));
29+
challenges.add(new Challenge("four", "five"));
30+
return new Authentication(challenges);
3231
}
3332

3433
@Test
3534
public void constructorWithListOfChallenges() {
3635
Authentication authentication = newChallengeAuthentication();
3736

38-
assertThat( "method not set correctly", authentication.getMethod(), is( equalTo( AuthenticationMethod.CHALLENGE ) ) );
39-
assertThat( "challenges list is null", authentication.getChallenges(), is( notNullValue() ) );
40-
assertThat( "challenges list is wrong size", authentication.getChallenges().size(), is( equalTo( challenges.size() ) ) );
41-
for ( int i = 0; i < challenges.size(); i++ ) {
42-
assertThat( "challenge question #" + i + " is not set correctly", authentication.getChallenges().get( i ).getQuestion(), is( equalTo( challenges.get( i ).getQuestion() ) ) );
43-
assertThat( "challenge answer #" + i + " is not set correctly", authentication.getChallenges().get( i ).getAnswer(), is( equalTo( challenges.get( i ).getAnswer() ) ) );
37+
assertThat("method not set correctly", authentication.getMethod(), is(AuthenticationMethod.CHALLENGE));
38+
assertThat("challenges list is null", authentication.getChallenges(), notNullValue());
39+
assertThat("challenges list is wrong size", authentication.getChallenges().size(), is(challenges.size()));
40+
for (int i = 0; i < challenges.size(); i++) {
41+
assertThat("challenge question #" + i + " is not set correctly", authentication.getChallenges().get(i).getQuestion(), is(challenges.get(i).getQuestion()));
42+
assertThat("challenge answer #" + i + " is not set correctly", authentication.getChallenges().get(i).getAnswer(), is(challenges.get(i).getAnswer()));
4443
}
4544
}
4645

4746
private String phoneNumber;
4847

4948
public Authentication newSMSAuthentication() {
5049
phoneNumber = "1234567890";
51-
return new Authentication( phoneNumber );
50+
return new Authentication(phoneNumber);
5251
}
5352

5453
@Test
5554
public void constructorWithTelephoneNumber() {
5655
Authentication authentication = newSMSAuthentication();
5756

58-
assertThat( "authentication method is not being set to sms", authentication.getMethod(), is( equalTo( AuthenticationMethod.SMS ) ) );
59-
assertThat( "phone number is not set correctly", authentication.getPhoneNumber(), is( equalTo( phoneNumber ) ) );
57+
assertThat("authentication method is not being set to sms", authentication.getMethod(), is(AuthenticationMethod.SMS));
58+
assertThat("phone number is not set correctly", authentication.getPhoneNumber(), is(phoneNumber));
6059
}
6160

6261
private Authentication newEmailAuthentication() {
63-
return new Authentication( AuthenticationMethod.EMAIL );
62+
return new Authentication(AuthenticationMethod.EMAIL);
6463
}
6564

6665
@Test
6766
public void emailAuthToAPIAuth() {
6867
Authentication authentication = newEmailAuthentication();
6968
Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication();
70-
assertThat("Null value was returned by converter", auth, is(notNullValue()));
71-
assertThat( "AuthScheme was not set to NONE", auth.getScheme(), is( equalTo( "NONE" ) ) );
69+
assertThat("Null value was returned by converter", auth, notNullValue());
70+
assertThat("AuthScheme was not set to NONE", auth.getScheme(), is("NONE"));
7271
}
7372

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

8887
@Test
8988
public void smsAuthToAPIAuth() {
9089
Authentication authentication = newSMSAuthentication();
9190
Auth auth = new AuthenticationConverter(authentication).toAPIAuthentication();
92-
assertThat("AuthScheme was not set to SMS", auth.getScheme(), is(equalTo("SMS")));
93-
assertThat( "Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue() );
94-
assertThat( "Challenges list was not length 1", auth.getChallenges().size(), is( equalTo( 1 ) ) );
95-
assertThat( "First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get( 0 ).getQuestion(), is( equalTo( phoneNumber ) ) );
96-
assertThat( "First challenge answer should be blank", auth.getChallenges().get( 0 ).getAnswer(), is( notNullValue() ) );
91+
assertThat("AuthScheme was not set to SMS", auth.getScheme(), is("SMS"));
92+
assertThat("Challenges list was null (should hold phone number)", auth.getChallenges(), notNullValue());
93+
assertThat("Challenges list was not length 1", auth.getChallenges().size(), is(1));
94+
assertThat("First challenge item should hold the phone number as question, but didn't", auth.getChallenges().get(0).getQuestion(), is(phoneNumber));
95+
assertThat("First challenge answer should be blank", auth.getChallenges().get(0).getAnswer(), notNullValue());
9796
}
9897
}

sdk/src/test/java/com/silanis/esl/sdk/CeremonyLayoutSettingsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void toAPILayoutOptions() {
125125
settings.setShowGlobalConfirmButton( true );
126126
settings.setShowGlobalDownloadButton( true );
127127
settings.setShowGlobalSaveAsLayoutButton( true );
128-
LayoutOptions layoutOptions = layoutOptions = new CeremonyLayoutSettingsConverter(settings).toAPILayoutOptions();
128+
LayoutOptions layoutOptions = new CeremonyLayoutSettingsConverter(settings).toAPILayoutOptions();
129129
assertThat( "", layoutOptions.getBrandingBar().getLogo().getLink(), is( equalTo( settings.getLogoImageLink() ) ) );
130130
}
131131

sdk/src/test/java/com/silanis/esl/sdk/DocumentTypeTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
import org.junit.Test;
44

55
import static org.hamcrest.MatcherAssert.assertThat;
6-
import static org.hamcrest.Matchers.equalTo;
76
import static org.hamcrest.Matchers.is;
87

98
public class DocumentTypeTest {
109

1110
@Test
1211
public void normalizingNameReplacesWhitespaceWithUnderscores() {
13-
assertThat(DocumentType.PDF.normalizeName("Some File.pdf"), is(equalTo("Some_File.pdf")));
12+
assertThat(DocumentType.PDF.normalizeName("Some File.pdf"), is("Some_File.pdf"));
1413
}
1514

1615
@Test
1716
public void appendsExtensionWhenNoneIsFound() {
18-
assertThat(DocumentType.PDF.normalizeName("Some File"), is(equalTo("Some_File.pdf")));
17+
assertThat(DocumentType.PDF.normalizeName("Some File"), is("Some_File.pdf"));
1918
}
2019

2120
@Test
2221
public void doesNotAppendExtraDotWhenOneIsFoundAtNameEnd() {
23-
assertThat(DocumentType.WORD.normalizeName("Some File."), is(equalTo("Some_File.docx")));
22+
assertThat(DocumentType.WORD.normalizeName("Some File."), is("Some_File.docx"));
2423
}
2524
}

sdk/src/test/java/com/silanis/esl/sdk/SenderInfoTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testToAPI() {
6363

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

66-
assertThat("first name was not properly set or retrieved", sender.getFirstName(), is(equalTo("firstName")));
66+
assertThat("first name was not properly set or retrieved", sender.getFirstName(), is("firstName"));
6767
assertThat( "last name was not properly set or retrieved", sender.getLastName(), is( equalTo( "lastName" ) ) );
6868
assertThat( "company was not properly set or retrieved", sender.getCompany(), is( equalTo( "company" ) ) );
6969
assertThat( "title was not properly set or retrieved", sender.getTitle(), is( equalTo( "title" ) ) );

sdk/src/test/java/com/silanis/esl/sdk/builder/AttachmentRequirementBuilderTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.junit.Test;
66

77
import static com.silanis.esl.sdk.builder.AttachmentRequirementBuilder.newAttachmentRequirementWithName;
8-
import static org.hamcrest.CoreMatchers.equalTo;
98
import static org.hamcrest.CoreMatchers.is;
109
import static org.hamcrest.MatcherAssert.assertThat;
1110

@@ -25,8 +24,8 @@ public void buildWithSpecificValues() {
2524
.isRequiredAttachment()
2625
.build();
2726

28-
assertThat("Attachment's name was not set correctly.", attachmentRequirement.getName(), is(equalTo(name)));
29-
assertThat("Attachment's description was not set correctly.", attachmentRequirement.getDescription(), is(equalTo(description)));
27+
assertThat("Attachment's name was not set correctly.", attachmentRequirement.getName(), is(name));
28+
assertThat("Attachment's description was not set correctly.", attachmentRequirement.getDescription(), is(description));
3029
assertThat("Attachment's required property was not set correctly", attachmentRequirement.isRequired(), is(isRequired));
3130
}
3231

0 commit comments

Comments
 (0)