// Path: sdk/src/main/java/com/stormpath/sdk/models/RegistrationForm.java
// public class RegistrationForm implements Serializable {
//     @Json(name = "givenName")
//     private String givenName;
// 
//     @Json(name = "surname")
//     private String surname;
// 
//     @Json(name = "email")
//     private String email;
// 
//     @Json(name = "password")
//     private String password;
// 
//     @Json(name = "username")
//     private String username;
// 
//     @Json(name = "customData")
//     private Map<String, String> customData;
// 
//     public RegistrationForm(String email, String password) {
//         this.email = email;
//         this.password = password;
//     }
// 
//     public String getGivenName() {
//         return givenName;
//     }
// 
//     public RegistrationForm setGivenName(String givenName) {
//         this.givenName = givenName;
//         return this;
//     }
// 
//     public String getSurname() {
//         return surname;
//     }
// 
//     public RegistrationForm setSurname(String surname) {
//         this.surname = surname;
//         return this;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public RegistrationForm setEmail(String email) {
//         this.email = email;
//         return this;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public RegistrationForm setPassword(String password) {
//         this.password = password;
//         return this;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public RegistrationForm setUsername(String username) {
//         this.username = username;
//         return this;
//     }
// 
//     public Map<String, String> getCustomData() {
//         return customData;
//     }
// 
//     public RegistrationForm setCustomData(Map<String, String> customData) {
//         this.customData = customData;
//         return this;
//     }
// }
// 
// 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);
//     }
// }


import com.stormpath.sdk.models.RegistrationForm;
import com.stormpath.sdk.models.StormpathError;
import com.stormpath.sdk.utils.ResourceUtils;
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;
        form.setGivenName("John");
        form.setSurname("Deere");
        Stormpath.register(form, mock(StormpathCallback.class));

        RecordedRequest request = takeLastRequest();

        assertThat(request.getMethod()).isEqualTo("POST");
        assertThat(request.getPath()).isEqualTo("/register");
        assertThat(request.getHeader("Accept")).isEqualTo("application/json");
        assertThat(request.getHeader("Content-Type")).isEqualTo("application/json; charset=utf-8");
        assertThat(request.getBody().readUtf8())
                .isEqualTo("{\"email\":\"john.deere@example.com\",\"givenName\":\"John\",\"password\":\"Test1234&\",\"surname\":\"Deere\"}");
    }

    @Test
    public void successfulRegistrationCallsSuccess() throws Exception {
        enqueueResponse("stormpath-register-response.json");
        StormpathCallback<Void> callback = mock(StormpathCallback.class);

        RegistrationForm form = new RegistrationForm("john.deere@example.com", "Test1234");
        form.setGivenName("John");
        form.setSurname("Deere");
        Stormpath.register(form, callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void successfulRegistrationSavesTokens() throws Exception {
        MockResponse mockResponse = new MockResponse()
// Path: sdk/src/main/java/com/stormpath/sdk/models/RegistrationForm.java
// public class RegistrationForm implements Serializable {
//     @Json(name = "givenName")
//     private String givenName;
// 
//     @Json(name = "surname")
//     private String surname;
// 
//     @Json(name = "email")
//     private String email;
// 
//     @Json(name = "password")
//     private String password;
// 
//     @Json(name = "username")
//     private String username;
// 
//     @Json(name = "customData")
//     private Map<String, String> customData;
// 
//     public RegistrationForm(String email, String password) {
//         this.email = email;
//         this.password = password;
//     }
// 
//     public String getGivenName() {
//         return givenName;
//     }
// 
//     public RegistrationForm setGivenName(String givenName) {
//         this.givenName = givenName;
//         return this;
//     }
// 
//     public String getSurname() {
//         return surname;
//     }
// 
//     public RegistrationForm setSurname(String surname) {
//         this.surname = surname;
//         return this;
//     }
// 
//     public String getEmail() {
//         return email;
//     }
// 
//     public RegistrationForm setEmail(String email) {
//         this.email = email;
//         return this;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public RegistrationForm setPassword(String password) {
//         this.password = password;
//         return this;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public RegistrationForm setUsername(String username) {
//         this.username = username;
//         return this;
//     }
// 
//     public Map<String, String> getCustomData() {
//         return customData;
//     }
// 
//     public RegistrationForm setCustomData(Map<String, String> customData) {
//         this.customData = customData;
//         return this;
//     }
// }
// 
// 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/RegisterTest.java
import com.stormpath.sdk.models.RegistrationForm;
import com.stormpath.sdk.models.StormpathError;
import com.stormpath.sdk.utils.ResourceUtils;
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;

        form.setGivenName("John");
        form.setSurname("Deere");
        Stormpath.register(form, mock(StormpathCallback.class));

        RecordedRequest request = takeLastRequest();

        assertThat(request.getMethod()).isEqualTo("POST");
        assertThat(request.getPath()).isEqualTo("/register");
        assertThat(request.getHeader("Accept")).isEqualTo("application/json");
        assertThat(request.getHeader("Content-Type")).isEqualTo("application/json; charset=utf-8");
        assertThat(request.getBody().readUtf8())
                .isEqualTo("{\"email\":\"john.deere@example.com\",\"givenName\":\"John\",\"password\":\"Test1234&\",\"surname\":\"Deere\"}");
    }

    @Test
    public void successfulRegistrationCallsSuccess() throws Exception {
        enqueueResponse("stormpath-register-response.json");
        StormpathCallback<Void> callback = mock(StormpathCallback.class);

        RegistrationForm form = new RegistrationForm("john.deere@example.com", "Test1234");
        form.setGivenName("John");
        form.setSurname("Deere");
        Stormpath.register(form, callback);

        verify(callback).onSuccess(null);
    }

    @Test
    public void successfulRegistrationSavesTokens() throws Exception {
        MockResponse mockResponse = new MockResponse()
                .setBody(ResourceUtils.readFromFile("stormpath-register-response.json"))