11package com .bandwidth ;
22
3+ import com .bandwidth .http .response .ApiResponse ;
34import com .bandwidth .multifactorauth .controllers .MFAController ;
45
56import com .bandwidth .multifactorauth .exceptions .ErrorWithRequestException ;
@@ -37,7 +38,10 @@ public void testMfaMessaging() throws Exception {
3738 .message ("Your temporary {NAME} {SCOPE} code is {CODE}" )
3839 .build ();
3940
40- TwoFactorMessagingResponse response = controller .createMessagingTwoFactor (ACCOUNT_ID , body ).getResult ();
41+ ApiResponse <TwoFactorMessagingResponse > apiResponse = controller .createMessagingTwoFactor (ACCOUNT_ID , body );
42+ assertEquals ("Response Code is not 200" , 200 , apiResponse .getStatusCode ());
43+
44+ TwoFactorMessagingResponse response = apiResponse .getResult ();
4145 assertNotNull ("MessageID is null" , response .getMessageId ());
4246 assertFalse ("MessageID is empty" , response .getMessageId ().isEmpty ());
4347 }
@@ -53,12 +57,15 @@ public void testMfaVoice() throws Exception {
5357 .message ("Your temporary {NAME} {SCOPE} code is {CODE}" )
5458 .build ();
5559
56- TwoFactorVoiceResponse response = controller .createVoiceTwoFactor (ACCOUNT_ID , body ).getResult ();
60+ ApiResponse <TwoFactorVoiceResponse > apiResponse = controller .createVoiceTwoFactor (ACCOUNT_ID , body );
61+ assertEquals ("Response Code is not 200" , 200 , apiResponse .getStatusCode ());
62+
63+ TwoFactorVoiceResponse response = apiResponse .getResult ();
5764 assertNotNull ("CallID is null" , response .getCallId ());
5865 assertFalse ("CallID is empty" , response .getCallId ().isEmpty ());
5966 }
6067
61- @ Test ( expected = ErrorWithRequestException . class )
68+ @ Test
6269 public void testMfaMessagingInvalidPhoneNumber () throws Exception {
6370 TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema .Builder ()
6471 .to ("+1invalid" )
@@ -69,10 +76,15 @@ public void testMfaMessagingInvalidPhoneNumber() throws Exception {
6976 .message ("Your temporary {NAME} {SCOPE} code is {CODE}" )
7077 .build ();
7178
72- controller .createMessagingTwoFactor (ACCOUNT_ID , body );
79+ ErrorWithRequestException e = assertThrows (
80+ "ErrorWithRequest Exception not thrown" ,
81+ ErrorWithRequestException .class ,
82+ ()->controller .createMessagingTwoFactor (ACCOUNT_ID , body )
83+ );
84+ assertEquals ("Response Code is not 400" , 400 , e .getResponseCode ());
7385 }
7486
75- @ Test ( expected = ErrorWithRequestException . class )
87+ @ Test
7688 public void testMfaVoiceInvalidPhoneNumber () throws Exception {
7789 TwoFactorCodeRequestSchema body = new TwoFactorCodeRequestSchema .Builder ()
7890 .to ("+1invalid" )
@@ -83,7 +95,12 @@ public void testMfaVoiceInvalidPhoneNumber() throws Exception {
8395 .message ("Your temporary {NAME} {SCOPE} code is {CODE}" )
8496 .build ();
8597
86- controller .createVoiceTwoFactor (ACCOUNT_ID , body );
98+ ErrorWithRequestException e = assertThrows (
99+ "ErrorWithRequest Exception not thrown" ,
100+ ErrorWithRequestException .class ,
101+ ()->controller .createVoiceTwoFactor (ACCOUNT_ID , body )
102+ );
103+ assertEquals ("Response Code not 400" , 400 , e .getResponseCode ());
87104 }
88105
89106 @ Test
@@ -99,11 +116,14 @@ public void testMfaVerify() throws Exception {
99116 .expirationTimeInMinutes (3 )
100117 .build ();
101118
102- TwoFactorVerifyCodeResponse response = controller .createVerifyTwoFactor (ACCOUNT_ID , body ).getResult ();
119+ ApiResponse <TwoFactorVerifyCodeResponse > apiResponse = controller .createVerifyTwoFactor (ACCOUNT_ID , body );
120+ assertEquals ("Response Code is not 200" , 200 , apiResponse .getStatusCode ());
121+
122+ TwoFactorVerifyCodeResponse response = apiResponse .getResult ();
103123 assertFalse ("Code should be invalid" , response .getValid ());
104124 }
105125
106- @ Test ( expected = ErrorWithRequestException . class )
126+ @ Test
107127 public void testMfaVerifyInvalidPhoneNumber () throws Exception {
108128 TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema .Builder ()
109129 .to ("+1invalid" )
@@ -113,6 +133,11 @@ public void testMfaVerifyInvalidPhoneNumber() throws Exception {
113133 .expirationTimeInMinutes (3 )
114134 .build ();
115135
116- controller .createVerifyTwoFactor (ACCOUNT_ID , body );
136+ ErrorWithRequestException e = assertThrows (
137+ "ErrorWithRequest Exception not thrown" ,
138+ ErrorWithRequestException .class ,
139+ ()->controller .createVerifyTwoFactor (ACCOUNT_ID , body )
140+ );
141+ assertEquals ("Response Code not 400" , 400 , e .getResponseCode ());
117142 }
118143}
0 commit comments