// Path: sdk/src/main/java/com/stormpath/sdk/models/StormpathError.java
// public class StormpathError implements Serializable {
// 
//     @Json(name = "status")
//     private int status;
// 
//     @Json(name = "message")
//     private String message;
// 
//     @Json(name = "code")
//     private int code;
// 
//     @Json(name = "developerMessage")
//     private String developerMessage;
// 
//     @Json(name = "moreInfo")
//     private String moreInfo;
// 
//     @Nullable
//     private transient Throwable throwable;
// 
//     /**
//      * Constructor for manually building an error when a local exception happens.
//      *
//      * @param message   a user-friendly message
//      * @param throwable the exception we caught
//      */
//     public StormpathError(String message, @NonNull Throwable throwable) {
//         this.throwable = throwable;
//         this.message = message;
//         this.developerMessage = throwable.getMessage();
//         this.status = -1;
//         this.code = -1;
//     }
// 
//     public int status() {
//         return status;
//     }
// 
//     /**
//      * @return an end-user error message
//      */
//     public String message() {
//         return message;
//     }
// 
//     public int code() {
//         return code;
//     }
// 
//     public String developerMessage() {
//         return developerMessage;
//     }
// 
//     public String moreInfo() {
//         return moreInfo;
//     }
// 
//     /**
//      * @return the throwable which caused the error, or null if the error was returned by the API
//      */
//     @Nullable
//     public Throwable throwable() {
//         return throwable;
//     }
// }


import com.stormpath.sdk.models.StormpathError;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.EOFException;
import java.net.HttpURLConnection;
import okhttp3.mockwebserver.RecordedRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.verify;
        verify(mockPlatform().preferenceStore()).setAccessToken("eyJraWQiOiI2WjA3NEJBQzhTM0tGWE5KOVhFTldEVUhGIiwiYWxnIjoiSFMyNTYifQ.eyJqdGk"
                + "iOiI1aW5La0tGNzhTeFg4T2cxbnRwbjZJIiwiaWF0IjoxNDU1NTI1MTg1LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9"
                + "ucy8yUnJxS25UaW91M1F3Tm50RTN0Y0VHIiwic3ViIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy81TXNRVEE0UVI5c0hZNnlRQlF"
                + "FSXlLIiwiZXhwIjoxNDU1NTI4Nzg1LCJydGkiOiI1MVcwc015Z0h3THQyVElsTFhKaGgwIn0.OUDaWC5xMyidkDX8FELAvvwDWk7-pWmUiUWQimPX3lA");
        verify(mockPlatform().preferenceStore()).setRefreshToken(
                "eyJraWQiOiI2WjA3NEJBQzhTM0tGWE5KOVhFTldEVUhGIiwiYWxnIjoiSFMyNTYifQ.eyJqdGkiOiI1MVcwc015Z0h3THQyVElsTFhKaGgwIiwiaWF0IjoxNDU"
                        + "1NTI1MTQ3LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9ucy8yUnJxS25UaW91M1F3Tm50RTN0Y0VHIiwic3V"
                        + "iIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy81TXNRVEE0UVI5c0hZNnlRQlFFSXlLIiwiZXhwIjoxNDYwNzA5MTQ3fQ."
                        + "g15poTJqau1nluVSCr0j-xnlqrQwySFOVX30mD_jw5A");
    }

    @Test
    public void successfulRefreshCallsSuccess() throws Exception {
        stub(mockPlatform().preferenceStore().getRefreshToken()).toReturn("abcdefghijklmnopqrstuwyxz0123456789");

        enqueueResponse("stormpath-refresh-token-response.json");
        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.refreshAccessToken(callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void failedRefreshCallsFailure() throws Exception {
        stub(mockPlatform().preferenceStore().getRefreshToken()).toReturn("abcdefghijklmnopqrstuwyxz0123456789");

        enqueueResponse("stormpath-refresh-token-400.json", HttpURLConnection.HTTP_BAD_REQUEST);
        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.refreshAccessToken(callback);

// Path: sdk/src/main/java/com/stormpath/sdk/models/StormpathError.java
// public class StormpathError implements Serializable {
// 
//     @Json(name = "status")
//     private int status;
// 
//     @Json(name = "message")
//     private String message;
// 
//     @Json(name = "code")
//     private int code;
// 
//     @Json(name = "developerMessage")
//     private String developerMessage;
// 
//     @Json(name = "moreInfo")
//     private String moreInfo;
// 
//     @Nullable
//     private transient Throwable throwable;
// 
//     /**
//      * Constructor for manually building an error when a local exception happens.
//      *
//      * @param message   a user-friendly message
//      * @param throwable the exception we caught
//      */
//     public StormpathError(String message, @NonNull Throwable throwable) {
//         this.throwable = throwable;
//         this.message = message;
//         this.developerMessage = throwable.getMessage();
//         this.status = -1;
//         this.code = -1;
//     }
// 
//     public int status() {
//         return status;
//     }
// 
//     /**
//      * @return an end-user error message
//      */
//     public String message() {
//         return message;
//     }
// 
//     public int code() {
//         return code;
//     }
// 
//     public String developerMessage() {
//         return developerMessage;
//     }
// 
//     public String moreInfo() {
//         return moreInfo;
//     }
// 
//     /**
//      * @return the throwable which caused the error, or null if the error was returned by the API
//      */
//     @Nullable
//     public Throwable throwable() {
//         return throwable;
//     }
// }


// Path: sdk/src/test/java/com/stormpath/sdk/RefreshTokenTest.java
import com.stormpath.sdk.models.StormpathError;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.EOFException;
import java.net.HttpURLConnection;
import okhttp3.mockwebserver.RecordedRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.verify;

        verify(mockPlatform().preferenceStore()).setAccessToken("eyJraWQiOiI2WjA3NEJBQzhTM0tGWE5KOVhFTldEVUhGIiwiYWxnIjoiSFMyNTYifQ.eyJqdGk"
                + "iOiI1aW5La0tGNzhTeFg4T2cxbnRwbjZJIiwiaWF0IjoxNDU1NTI1MTg1LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9"
                + "ucy8yUnJxS25UaW91M1F3Tm50RTN0Y0VHIiwic3ViIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy81TXNRVEE0UVI5c0hZNnlRQlF"
                + "FSXlLIiwiZXhwIjoxNDU1NTI4Nzg1LCJydGkiOiI1MVcwc015Z0h3THQyVElsTFhKaGgwIn0.OUDaWC5xMyidkDX8FELAvvwDWk7-pWmUiUWQimPX3lA");
        verify(mockPlatform().preferenceStore()).setRefreshToken(
                "eyJraWQiOiI2WjA3NEJBQzhTM0tGWE5KOVhFTldEVUhGIiwiYWxnIjoiSFMyNTYifQ.eyJqdGkiOiI1MVcwc015Z0h3THQyVElsTFhKaGgwIiwiaWF0IjoxNDU"
                        + "1NTI1MTQ3LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9ucy8yUnJxS25UaW91M1F3Tm50RTN0Y0VHIiwic3V"
                        + "iIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy81TXNRVEE0UVI5c0hZNnlRQlFFSXlLIiwiZXhwIjoxNDYwNzA5MTQ3fQ."
                        + "g15poTJqau1nluVSCr0j-xnlqrQwySFOVX30mD_jw5A");
    }

    @Test
    public void successfulRefreshCallsSuccess() throws Exception {
        stub(mockPlatform().preferenceStore().getRefreshToken()).toReturn("abcdefghijklmnopqrstuwyxz0123456789");

        enqueueResponse("stormpath-refresh-token-response.json");
        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.refreshAccessToken(callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void failedRefreshCallsFailure() throws Exception {
        stub(mockPlatform().preferenceStore().getRefreshToken()).toReturn("abcdefghijklmnopqrstuwyxz0123456789");

        enqueueResponse("stormpath-refresh-token-400.json", HttpURLConnection.HTTP_BAD_REQUEST);
        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.refreshAccessToken(callback);

        verify(callback).onFailure(any(StormpathError.class));