1919import cucumber .api .java .en .Then ;
2020
2121import static org .hamcrest .CoreMatchers .is ;
22-
23- import static org .junit .Assert .assertThat ;
24- import static org .junit .Assert .assertTrue ;
25- import static org .junit .Assert .fail ;
22+ import static org .junit .Assert .*;
2623
2724public class CallTest {
2825 private String origJSON ;
26+ private String otherJSON = "{ \" uri\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\" , \" dateCreated\" : \" Tue, 12 Aug 2014 08:02:17 GMT\" , \" dateUpdated\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" revision\" : 1, \" callId\" : \" CA42ed11f93dc08b952027ffbc40600000\" , \" parentcallId\" : null, \" accountId\" : \" AC142c48f2ee663e214c19ea459516068c\" , \" to\" : \" +14153855708\" , \" from\" : \" +14158141819\" , \" phoneNumberId\" : null, \" status\" : \" completed\" , \" startTime\" : \" Tue, 12 Aug 2014 08:02:31 GMT\" , \" connectTime\" : \" Tue, 12 Aug 2014 08:02:50 GMT\" , \" endTime\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" duration\" : 16, \" connectDuration\" : 13, \" direction\" : \" outboundAPI\" , \" answeredBy\" : null, \" callerName\" : null, \" subresourceUris\" : { \t \" notifications\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\" , \t \" recordings\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }" ;
2927 private Call theCall ;
3028
3129 @ Given ("^Some JSON representing a call.$" )
3230 public void storeJSON () {
33- this .origJSON = "{ \" uri\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\" , \" dateCreated\" : \" Tue, 12 Aug 2014 08:02:17 GMT\" , \" dateUpdated\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" revision\" : 1, \" callId\" : \" CA42ed11f93dc08b952027ffbc406d0868\" , \" parentcallId\" : null, \" accountId\" : \" AC142c48f2ee663e214c19ea459516068c\" , \" to\" : \" +14153855708\" , \" from\" : \" +14158141819\" , \" phoneNumberId\" : null, \" status\" : \" completed\" , \" startTime\" : \" Tue, 12 Aug 2014 08:02:31 GMT\" , \" endTime\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" duration\" : \" 16 \" , \" direction\" : \" outboundAPI\" , \" answeredBy\" : null, \" callerName\" : null, \" subresourceUris\" : { \t \" notifications\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\" , \t \" recordings\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }" ;
31+ this .origJSON = "{ \" uri\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\" , \" dateCreated\" : \" Tue, 12 Aug 2014 08:02:17 GMT\" , \" dateUpdated\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" revision\" : 1, \" callId\" : \" CA42ed11f93dc08b952027ffbc406d0868\" , \" parentcallId\" : null, \" accountId\" : \" AC142c48f2ee663e214c19ea459516068c\" , \" to\" : \" +14153855708\" , \" from\" : \" +14158141819\" , \" phoneNumberId\" : null, \" status\" : \" completed\" , \" startTime\" : \" Tue, 12 Aug 2014 08:02:31 GMT\" , \" connectTime \" : \" Tue, 12 Aug 2014 08:02:50 GMT \" , \" endTime\" : \" Tue, 12 Aug 2014 08:02:47 GMT\" , \" duration\" : 16, \" connectDuration \" : 13 , \" direction\" : \" outboundAPI\" , \" answeredBy\" : null, \" callerName\" : null, \" subresourceUris\" : { \t \" notifications\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\" , \t \" recordings\" : \" /Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }" ;
3432 }
3533
3634 @ Then ("^build a Call object from that JSON.$" )
@@ -59,11 +57,16 @@ public void checkCallAgainstJson() {
5957 PersyDateFormat .format (this .theCall .getStartTime (), dateString , new FieldPosition (0 ));
6058 assertThat ((String )jsonMap .get ("startTime" ), is (dateString .toString ()));
6159
60+ dateString = new StringBuffer ();
61+ PersyDateFormat .format (this .theCall .getConnectTime (), dateString , new FieldPosition (0 ));
62+ assertThat ((String )jsonMap .get ("connectTime" ), is (dateString .toString ()));
63+
6264 dateString = new StringBuffer ();
6365 PersyDateFormat .format (this .theCall .getEndTime (), dateString , new FieldPosition (0 ));
6466 assertThat ((String )jsonMap .get ("endTime" ), is (dateString .toString ()));
6567
66- assertThat ((Integer )jsonMap .get ("durationSec" ), is (this .theCall .getDurationSec ()));
68+ assertThat ((Integer ) ((Double ) jsonMap .get ("duration" )).intValue (), is (this .theCall .getDuration ()));
69+ assertThat ((Integer ) ((Double ) jsonMap .get ("connectDuration" )).intValue (), is (this .theCall .getConnectDuration ()));
6770
6871 String outboundAPI = gson .toJson (Direction .OUTBOUND_API );
6972 outboundAPI = outboundAPI .substring (1 ,outboundAPI .length ()-1 );
@@ -77,4 +80,13 @@ public void checkCallAgainstJson() {
7780 assertThat ((String )mmm .get ("recordings" ), is (this .theCall .getSubresourceUris ().get ("recordings" )));
7881 assertThat ((String )mmm .get ("notifications" ), is (this .theCall .getSubresourceUris ().get ("notifications" )));
7982 }
83+
84+ @ Then ("^check the call is( not)? equal.$" )
85+ public void checkEqual (String not ) throws Throwable {
86+ if (not == null ) {
87+ assertTrue (this .theCall .equals (Call .fromJson (origJSON )));
88+ } else {
89+ assertFalse (this .theCall .equals (Call .fromJson (otherJSON )));
90+ }
91+ }
8092}
0 commit comments