// 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/utils/ResourceUtils.java
// public class ResourceUtils {
// 
//     private static final String MOCK_DATA_DIRECTORY = "mockdata/%s";
// 
//     private ResourceUtils() {
//     }
// 
//     /**
//      * Converts InputStream to String.
//      */
//     public static String convertStreamToString(InputStream is) {
//         Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
//         return s.hasNext() ? s.next() : "";
//     }
// 
//     /**
//      * Reads a resource file to <code>String</code>.
//      */
//     public static String readFromFile(String filename) {
//         InputStream is = ResourceUtils.class.getClassLoader().getResourceAsStream(String.format(MOCK_DATA_DIRECTORY, filename));
//         return convertStreamToString(is);
//     }
// }
// 
// Path: sdk/src/test/java/com/stormpath/sdk/utils/StormpathTestCallback.java
// public class StormpathTestCallback<T> implements StormpathCallback<T> {
// 
//     public T response;
// 
//     public StormpathError error;
// 
//     @Override
//     public void onSuccess(T t) {
//         this.response = t;
//     }
// 
//     @Override
//     public void onFailure(StormpathError error) {
//         this.error = error;
//     }
// }


import com.stormpath.sdk.models.StormpathError;
import com.stormpath.sdk.utils.ResourceUtils;
import com.stormpath.sdk.utils.StormpathTestCallback;
import org.junit.Test;
import java.net.HttpURLConnection;
import okhttp3.mockwebserver.MockResponse;
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.verify;
                + "ltFz1735IRnD0vIgdeKC4oInxe8K0KzhDJ95RgRuqmA";

        MockResponse mockResponse = new MockResponse()
                .setBody(ResourceUtils.readFromFile("stormpath-login-response.json"))
                .addHeader("Set-Cookie: access_token=" + accessToken + "; path=/; expires=Fri, 12 Feb 2016 18:03:56 GMT; httponly")
                .addHeader("Set-Cookie: refresh_token=" + refreshToken + "; path=/; expires=Tue, 12 Apr 2016 17:03:56 GMT; httponly");
        enqueueResponse(mockResponse);

        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.loginWithProvider("facebook", "1234", callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void failedLoginCallsFailure() throws Exception {
        enqueueResponse("stormpath-login-400.json", HttpURLConnection.HTTP_BAD_REQUEST);
        StormpathTestCallback<Void> callback = new StormpathTestCallback<>();
        Stormpath.loginWithProvider("facebook", "1234", callback);

        assertThat(callback.error.code()).isEqualTo(7100);
        assertThat(callback.error.status()).isEqualTo(400);
        assertThat(callback.error.developerMessage()).isEqualTo("Login attempt failed because the specified password is incorrect.");
        assertThat(callback.error.message()).isEqualTo("Invalid username or password.");
        assertThat(callback.error.moreInfo()).isEqualTo("http://docs.stormpath.com/errors/7100");
    }

    @Test
    public void failedDeserializationCallsFailure() throws Exception {
        enqueueEmptyResponse(HttpURLConnection.HTTP_OK);
// 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/utils/ResourceUtils.java
// public class ResourceUtils {
// 
//     private static final String MOCK_DATA_DIRECTORY = "mockdata/%s";
// 
//     private ResourceUtils() {
//     }
// 
//     /**
//      * Converts InputStream to String.
//      */
//     public static String convertStreamToString(InputStream is) {
//         Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
//         return s.hasNext() ? s.next() : "";
//     }
// 
//     /**
//      * Reads a resource file to <code>String</code>.
//      */
//     public static String readFromFile(String filename) {
//         InputStream is = ResourceUtils.class.getClassLoader().getResourceAsStream(String.format(MOCK_DATA_DIRECTORY, filename));
//         return convertStreamToString(is);
//     }
// }
// 
// Path: sdk/src/test/java/com/stormpath/sdk/utils/StormpathTestCallback.java
// public class StormpathTestCallback<T> implements StormpathCallback<T> {
// 
//     public T response;
// 
//     public StormpathError error;
// 
//     @Override
//     public void onSuccess(T t) {
//         this.response = t;
//     }
// 
//     @Override
//     public void onFailure(StormpathError error) {
//         this.error = error;
//     }
// }


// Path: sdk/src/test/java/com/stormpath/sdk/SocialLoginTest.java
import com.stormpath.sdk.models.StormpathError;
import com.stormpath.sdk.utils.ResourceUtils;
import com.stormpath.sdk.utils.StormpathTestCallback;
import org.junit.Test;
import java.net.HttpURLConnection;
import okhttp3.mockwebserver.MockResponse;
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.verify;

                + "ltFz1735IRnD0vIgdeKC4oInxe8K0KzhDJ95RgRuqmA";

        MockResponse mockResponse = new MockResponse()
                .setBody(ResourceUtils.readFromFile("stormpath-login-response.json"))
                .addHeader("Set-Cookie: access_token=" + accessToken + "; path=/; expires=Fri, 12 Feb 2016 18:03:56 GMT; httponly")
                .addHeader("Set-Cookie: refresh_token=" + refreshToken + "; path=/; expires=Tue, 12 Apr 2016 17:03:56 GMT; httponly");
        enqueueResponse(mockResponse);

        StormpathCallback<Void> callback = mock(StormpathCallback.class);
        Stormpath.loginWithProvider("facebook", "1234", callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void failedLoginCallsFailure() throws Exception {
        enqueueResponse("stormpath-login-400.json", HttpURLConnection.HTTP_BAD_REQUEST);
        StormpathTestCallback<Void> callback = new StormpathTestCallback<>();
        Stormpath.loginWithProvider("facebook", "1234", callback);

        assertThat(callback.error.code()).isEqualTo(7100);
        assertThat(callback.error.status()).isEqualTo(400);
        assertThat(callback.error.developerMessage()).isEqualTo("Login attempt failed because the specified password is incorrect.");
        assertThat(callback.error.message()).isEqualTo("Invalid username or password.");
        assertThat(callback.error.moreInfo()).isEqualTo("http://docs.stormpath.com/errors/7100");
    }

    @Test
    public void failedDeserializationCallsFailure() throws Exception {
        enqueueEmptyResponse(HttpURLConnection.HTTP_OK);
        StormpathTestCallback<Void> callback = new StormpathTestCallback<>();