Skip to content

Commit 916fd8b

Browse files
Changed Repeated Object References To Builder Pattern
Most of the tests were using repeated references to an object when initializing its state. Changed to the builder pattern to clean things up.
1 parent 1becb2b commit 916fd8b

File tree

4 files changed

+93
-78
lines changed

4 files changed

+93
-78
lines changed

src/test/java/com/bandwidth/MessagingApiTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ public void initTest(){
3838
public void testCreateMessage() throws Exception {
3939
final String text = "Java Test";
4040

41-
MessageRequest body = new MessageRequest();
42-
body.setTo(Collections.singletonList(USER_NUMBER));
43-
body.setFrom(BW_NUMBER);
44-
body.setText(text);
45-
body.setApplicationId(MESSAGING_APPLICATION_ID);
41+
MessageRequest body = new MessageRequest.Builder()
42+
.to(Collections.singletonList(USER_NUMBER))
43+
.from(BW_NUMBER)
44+
.text(text)
45+
.applicationId(MESSAGING_APPLICATION_ID)
46+
.build();
4647

4748
BandwidthMessage response = controller.createMessage(ACCOUNT_ID, body).getResult();
4849
assertEquals("Application ID not equal", MESSAGING_APPLICATION_ID, response.getApplicationId());
@@ -53,11 +54,12 @@ public void testCreateMessage() throws Exception {
5354

5455
@Test(expected = MessagingException.class)
5556
public void testCreateMessageInvalidPhoneNumber() throws Exception {
56-
MessageRequest body = new MessageRequest();
57-
body.setTo(Collections.singletonList("+1invalid"));
58-
body.setFrom(BW_NUMBER);
59-
body.setText("Java Test");
60-
body.setApplicationId(MESSAGING_APPLICATION_ID);
57+
MessageRequest body = new MessageRequest.Builder()
58+
.to(Collections.singletonList("+1invalid"))
59+
.from(BW_NUMBER)
60+
.text("Java Test")
61+
.applicationId(MESSAGING_APPLICATION_ID)
62+
.build();
6163

6264
controller.createMessage(ACCOUNT_ID, body);
6365
}

src/test/java/com/bandwidth/MfaApiTests.java

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,83 @@ public void initTest(){
3030

3131
@Test
3232
public void testMfaMessaging() throws Exception {
33-
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema();
34-
body.setTo(USER_NUMBER);
35-
body.setFrom(BW_NUMBER);
36-
body.setApplicationId(MESSAGING_APPLICATION_ID);
37-
body.setScope("scope");
38-
body.setDigits(6);
39-
body.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
33+
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema.Builder()
34+
.to(USER_NUMBER)
35+
.from(BW_NUMBER)
36+
.applicationId(MESSAGING_APPLICATION_ID)
37+
.scope("scope")
38+
.digits(6)
39+
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
40+
.build();
4041

4142
controller.createMessagingTwoFactor(ACCOUNT_ID, body);
4243
}
4344

4445
@Test
4546
public void testMfaVoice() throws Exception {
46-
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema();
47-
body.setTo(USER_NUMBER);
48-
body.setFrom(BW_NUMBER);
49-
body.setApplicationId(VOICE_APPLICATION_ID);
50-
body.setScope("scope");
51-
body.setDigits(6);
52-
body.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
47+
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema.Builder()
48+
.to(USER_NUMBER)
49+
.from(BW_NUMBER)
50+
.applicationId(VOICE_APPLICATION_ID)
51+
.scope("scope")
52+
.digits(6)
53+
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
54+
.build();
5355

5456
controller.createVoiceTwoFactor(ACCOUNT_ID, body);
5557
}
5658

5759
@Test(expected = ErrorWithRequestException.class)
5860
public void testMfaMessagingInvalidPhoneNumber() throws Exception {
59-
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema();
60-
body.setTo("+1invalid");
61-
body.setFrom(BW_NUMBER);
62-
body.setApplicationId(MESSAGING_APPLICATION_ID);
63-
body.setScope("scope");
64-
body.setDigits(6);
65-
body.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
61+
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema.Builder()
62+
.to("+1invalid")
63+
.from(BW_NUMBER)
64+
.applicationId(MESSAGING_APPLICATION_ID)
65+
.scope("scope")
66+
.digits(6)
67+
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
68+
.build();
6669

6770
controller.createMessagingTwoFactor(ACCOUNT_ID, body);
6871
}
6972

7073
@Test(expected = ErrorWithRequestException.class)
7174
public void testMfaVoiceInvalidPhoneNumber() throws Exception {
72-
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema();
73-
body.setTo("+1invalid");
74-
body.setFrom(BW_NUMBER);
75-
body.setApplicationId(VOICE_APPLICATION_ID);
76-
body.setScope("scope");
77-
body.setDigits(6);
78-
body.setMessage("Your temporary {NAME} {SCOPE} code is {CODE}");
75+
TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema.Builder()
76+
.to("+1invalid")
77+
.from(BW_NUMBER)
78+
.applicationId(VOICE_APPLICATION_ID)
79+
.scope("scope")
80+
.digits(6)
81+
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
82+
.build();
7983

8084
controller.createVoiceTwoFactor(ACCOUNT_ID, body);
8185
}
8286

8387
@Test
8488
public void testMfaVerify() throws Exception {
8589

86-
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema();
87-
body.setTo(USER_NUMBER);
88-
body.setApplicationId(VOICE_APPLICATION_ID);
89-
body.setScope("scope");
90-
body.setCode("1234567");
91-
body.setExpirationTimeInMinutes(3);
90+
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema.Builder()
91+
.to(USER_NUMBER)
92+
.applicationId(VOICE_APPLICATION_ID)
93+
.scope("scope")
94+
.code("1234567")
95+
.expirationTimeInMinutes(3)
96+
.build();
9297

9398
controller.createVerifyTwoFactor(ACCOUNT_ID, body);
9499
}
95100

96101
@Test(expected = ErrorWithRequestException.class)
97102
public void testMfaVerifyInvalidPhoneNumber() throws Exception {
98-
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema();
99-
body.setTo("+1invalid");
100-
body.setApplicationId(VOICE_APPLICATION_ID);
101-
body.setScope("scope");
102-
body.setCode("123456");
103-
body.setExpirationTimeInMinutes(3);
103+
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema.Builder()
104+
.to("+1invalid")
105+
.applicationId(VOICE_APPLICATION_ID)
106+
.scope("scope")
107+
.code("123456")
108+
.expirationTimeInMinutes(3)
109+
.build();
104110

105111
controller.createVerifyTwoFactor(ACCOUNT_ID, body);
106112
}

src/test/java/com/bandwidth/TnLookupApiTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ public void initTest(){
2626

2727
@Test
2828
public void testPhoneNumberLookup() throws Exception {
29-
OrderRequest body = new OrderRequest();
30-
body.setTns(Collections.singletonList(USER_NUMBER));
29+
OrderRequest body = new OrderRequest.Builder()
30+
.tns(Collections.singletonList(USER_NUMBER))
31+
.build();
32+
3133
OrderResponse orderResponse = controller.createLookupRequest(ACCOUNT_ID, body).getResult();
34+
3235
controller.getLookupRequestStatus(ACCOUNT_ID, orderResponse.getRequestId());
3336
}
3437
}

src/test/java/com/bandwidth/VoiceApiTests.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public void initTest(){
2929
public void testCreateCallAndGetCallState() throws Exception {
3030
final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound");
3131

32-
CreateCallRequest body = new CreateCallRequest();
33-
body.setTo(USER_NUMBER);
34-
body.setFrom(BW_NUMBER);
35-
body.setApplicationId(VOICE_APPLICATION_ID);
36-
body.setAnswerUrl(answerUrl);
32+
CreateCallRequest body = new CreateCallRequest.Builder()
33+
.to(USER_NUMBER)
34+
.from(BW_NUMBER)
35+
.applicationId(VOICE_APPLICATION_ID)
36+
.answerUrl(answerUrl)
37+
.build();
3738

3839
CreateCallResponse createCallResponse = controller.createCall(ACCOUNT_ID, body).getResult();
3940
assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId());
@@ -54,22 +55,24 @@ public void testCreateCallWithAmdAndGetCallState() throws Exception {
5455
final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound");
5556
final String machineDetectionUrl = BASE_CALLBACK_URL.concat("/callbacks/machineDetection");
5657

57-
MachineDetectionConfiguration machineDetection = new MachineDetectionConfiguration();
58-
machineDetection.setMode(ModeEnum.ASYNC);
59-
machineDetection.setCallbackUrl(machineDetectionUrl);
60-
machineDetection.setCallbackMethod(CallbackMethodEnum.POST);
61-
machineDetection.setDetectionTimeout(5.0);
62-
machineDetection.setSilenceTimeout(5.0);
63-
machineDetection.setSpeechThreshold(5.0);
64-
machineDetection.setSpeechEndThreshold(5.0);
65-
machineDetection.setDelayResult(true);
66-
67-
CreateCallRequest body = new CreateCallRequest();
68-
body.setTo(USER_NUMBER);
69-
body.setFrom(BW_NUMBER);
70-
body.setApplicationId(VOICE_APPLICATION_ID);
71-
body.setAnswerUrl(answerUrl);
72-
body.setMachineDetection(machineDetection);
58+
MachineDetectionConfiguration machineDetectionConfiguration = new MachineDetectionConfiguration.Builder()
59+
.mode(ModeEnum.ASYNC)
60+
.callbackUrl(machineDetectionUrl)
61+
.callbackMethod(CallbackMethodEnum.POST)
62+
.detectionTimeout(5.0)
63+
.silenceTimeout(5.0)
64+
.speechThreshold(5.0)
65+
.speechEndThreshold(5.0)
66+
.delayResult(true)
67+
.build();
68+
69+
CreateCallRequest body = new CreateCallRequest.Builder()
70+
.to(USER_NUMBER)
71+
.from(BW_NUMBER)
72+
.applicationId(VOICE_APPLICATION_ID)
73+
.answerUrl(answerUrl)
74+
.machineDetection(machineDetectionConfiguration)
75+
.build();
7376

7477
CreateCallResponse createCallResponse = controller.createCall(ACCOUNT_ID, body).getResult();
7578
assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId());
@@ -88,11 +91,12 @@ public void testCreateCallWithAmdAndGetCallState() throws Exception {
8891
public void testCreateCallInvalidPhoneNumber() throws Exception {
8992
final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound");
9093

91-
CreateCallRequest body = new CreateCallRequest();
92-
body.setTo("+1invalid");
93-
body.setFrom(BW_NUMBER);
94-
body.setApplicationId(VOICE_APPLICATION_ID);
95-
body.setAnswerUrl(answerUrl);
94+
CreateCallRequest body = new CreateCallRequest.Builder()
95+
.to("+1invalid")
96+
.from(BW_NUMBER)
97+
.applicationId(VOICE_APPLICATION_ID)
98+
.answerUrl(answerUrl)
99+
.build();
96100

97101
controller.createCall(ACCOUNT_ID, body);
98102
}

0 commit comments

Comments
 (0)