package com.box.sdk;

import java.net.MalformedURLException;
import java.net.URL;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

import com.github.tomakehurst.wiremock.junit.WireMockRule;

public class BoxAPIRequestTest {
    @Rule
    public WireMockRule wireMockRule = new WireMockRule(8080);

    @Test
    @Category(UnitTest.class)
    public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns500() throws MalformedURLException {
        stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(500)));
        Time mockTime = mock(Time.class);
        BackoffCounter backoffCounter = new BackoffCounter(mockTime);

        URL url = new URL("http://localhost:8080/");
        BoxAPIRequest request = new BoxAPIRequest(url, "GET");
        request.setBackoffCounter(backoffCounter);

        try {
            request.send();
        } catch (BoxAPIException e) {
            verify(BoxAPIConnection.DEFAULT_MAX_ATTEMPTS, getRequestedFor(urlEqualTo("/")));
        }
    }
}

@@ -1213,11 +1213,1543 @@
  %7D%0A    %7D
+%0A%0A    @Test%0A    @Category(UnitTest.class)%0A    public void requestRetriesTheDefaultNumberOfTimesWhenServerReturns429() throws MalformedURLException %7B%0A        stubFor(get(urlEqualTo(%22/%22)).willReturn(aResponse().withStatus(429)));%0A        Time mockTime = mock(Time.class);%0A        BackoffCounter backoffCounter = new BackoffCounter(mockTime);%0A%0A        URL url = new URL(%22http://localhost:8080/%22);%0A        BoxAPIRequest request = new BoxAPIRequest(url, %22GET%22);%0A        request.setBackoffCounter(backoffCounter);%0A%0A        try %7B%0A            request.send();%0A        %7D catch (BoxAPIException e) %7B%0A            verify(BoxAPIConnection.DEFAULT_MAX_ATTEMPTS, getRequestedFor(urlEqualTo(%22/%22)));%0A        %7D%0A    %7D%0A%0A    @Test%0A    @Category(UnitTest.class)%0A    public void requestRetriesTheNumberOfTimesConfiguredInTheAPIConnection() throws MalformedURLException %7B%0A        final int expectedNumAttempts = 1;%0A        stubFor(get(urlEqualTo(%22/%22)).willReturn(aResponse().withStatus(500)));%0A        Time mockTime = mock(Time.class);%0A        BackoffCounter backoffCounter = new BackoffCounter(mockTime);%0A%0A        BoxAPIConnection api = new BoxAPIConnection(%22%22);%0A        api.setMaxAttempts(expectedNumAttempts);%0A%0A        URL url = new URL(%22http://localhost:8080/%22);%0A        BoxAPIRequest request = new BoxAPIRequest(api, url, %22GET%22);%0A        request.setBackoffCounter(backoffCounter);%0A%0A        try %7B%0A            request.send();%0A        %7D catch (BoxAPIException e) %7B%0A            verify(expectedNumAttempts, getRequestedFor(urlEqualTo(%22/%22)));%0A        %7D%0A    %7D
 %0A%7D%0A

Add more unit tests for auto-retry