@@ -36,4 +36,44 @@ public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns500() throws M
3636 verify (BoxAPIConnection .DEFAULT_MAX_ATTEMPTS , getRequestedFor (urlEqualTo ("/" )));
3737 }
3838 }
39+
40+ @ Test
41+ @ Category (UnitTest .class )
42+ public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns429 () throws MalformedURLException {
43+ stubFor (get (urlEqualTo ("/" )).willReturn (aResponse ().withStatus (429 )));
44+ Time mockTime = mock (Time .class );
45+ BackoffCounter backoffCounter = new BackoffCounter (mockTime );
46+
47+ URL url = new URL ("http://localhost:8080/" );
48+ BoxAPIRequest request = new BoxAPIRequest (url , "GET" );
49+ request .setBackoffCounter (backoffCounter );
50+
51+ try {
52+ request .send ();
53+ } catch (BoxAPIException e ) {
54+ verify (BoxAPIConnection .DEFAULT_MAX_ATTEMPTS , getRequestedFor (urlEqualTo ("/" )));
55+ }
56+ }
57+
58+ @ Test
59+ @ Category (UnitTest .class )
60+ public void requestRetriesTheNumberOfTimesConfiguredInTheAPIConnection () throws MalformedURLException {
61+ final int expectedNumAttempts = 1 ;
62+ stubFor (get (urlEqualTo ("/" )).willReturn (aResponse ().withStatus (500 )));
63+ Time mockTime = mock (Time .class );
64+ BackoffCounter backoffCounter = new BackoffCounter (mockTime );
65+
66+ BoxAPIConnection api = new BoxAPIConnection ("" );
67+ api .setMaxAttempts (expectedNumAttempts );
68+
69+ URL url = new URL ("http://localhost:8080/" );
70+ BoxAPIRequest request = new BoxAPIRequest (api , url , "GET" );
71+ request .setBackoffCounter (backoffCounter );
72+
73+ try {
74+ request .send ();
75+ } catch (BoxAPIException e ) {
76+ verify (expectedNumAttempts , getRequestedFor (urlEqualTo ("/" )));
77+ }
78+ }
3979}
0 commit comments