// Path: src/com/pocketreddit/library/authentication/LoginResult.java
// public class LoginResult {
//     private String modHash;
//     private String cookie;
//     private List<List<String>> errors;
// 
//     public LoginResult(String json) throws AuthenticationException, JSONException {
//         this(new JSONObject(json));
//     }
// 
//     public LoginResult(JSONObject json) throws AuthenticationException {
//         try {
//             errors = new ArrayList<List<String>>();
//             json = json.getJSONObject("json");
// 
//             JSONArray jsonErrors = json.getJSONArray("errors");
//             for (int i = 0; i < jsonErrors.length(); i++) {
//                 JSONArray currentError = jsonErrors.getJSONArray(i);
//                 List<String> errorKeys = new ArrayList<String>();
//                 for (int j = 0; j < currentError.length(); j++) {
//                     errorKeys.add(currentError.getString(j));
//                 }
// 
//                 errors.add(errorKeys);
//             }
// 
//             if (jsonErrors.length() == 0) {
//                 JSONObject data = json.getJSONObject("data");
//                 setModHash(data.getString("modhash"));
//                 setCookie(data.getString("cookie"));
//             }
//         } catch (JSONException e) {
//             throw new AuthenticationException("Could not parse login response.", e);
//         }
//     }
// 
//     public String getModHash() {
//         return modHash;
//     }
// 
//     public void setModHash(String modHash) {
//         this.modHash = modHash;
//     }
// 
//     public String getCookie() {
//         return cookie;
//     }
// 
//     public void setCookie(String cookie) {
//         this.cookie = cookie;
//     }
// 
//     public List<List<String>> getErrors() {
//         return errors;
//     }
// 
//     public void setErrors(List<List<String>> errors) {
//         this.errors = errors;
//     }
// }


import com.pocketreddit.library.authentication.LoginResult;
import android.test.AndroidTestCase;
import android.util.Log;
package com.pocketreddit.library.authentication;



public class TestLoginResult extends AndroidTestCase {
    private static final String TAG = TestLoginResult.class.getName();

    private final String successfulLoginJson = "{\"json\": {\"errors\": [], \"data\": {\"modhash\": \"7l7jf0fzvt9556d747b9ef00409e1a90d2fbdc328cd26b599b\", \"cookie\": \"13829964,2012-07-05T10:56:57,3acfec8427be44b0b90970d59a56e1b50ff74adf\"}}}";
    private final String badPasswordJson = "{\"json\": {\"errors\": [[\"WRONG_PASSWORD\", \"invalid password\", \"passwd\"]]}}";

    public void testLoginResultFromSuccess() {
        try {
            LoginResult login = new LoginResult(successfulLoginJson);
            assertTrue("LoginResult shouldn't produce any errors.", login.getErrors().isEmpty());
        } catch (Exception e) {
            Log.e(TAG, "Failed parsing login response.", e);
            fail("Failed parsing login response.");
        }
    }

    public void testLoginResultBadPw() {
        try {
// Path: src/com/pocketreddit/library/authentication/LoginResult.java
// public class LoginResult {
//     private String modHash;
//     private String cookie;
//     private List<List<String>> errors;
// 
//     public LoginResult(String json) throws AuthenticationException, JSONException {
//         this(new JSONObject(json));
//     }
// 
//     public LoginResult(JSONObject json) throws AuthenticationException {
//         try {
//             errors = new ArrayList<List<String>>();
//             json = json.getJSONObject("json");
// 
//             JSONArray jsonErrors = json.getJSONArray("errors");
//             for (int i = 0; i < jsonErrors.length(); i++) {
//                 JSONArray currentError = jsonErrors.getJSONArray(i);
//                 List<String> errorKeys = new ArrayList<String>();
//                 for (int j = 0; j < currentError.length(); j++) {
//                     errorKeys.add(currentError.getString(j));
//                 }
// 
//                 errors.add(errorKeys);
//             }
// 
//             if (jsonErrors.length() == 0) {
//                 JSONObject data = json.getJSONObject("data");
//                 setModHash(data.getString("modhash"));
//                 setCookie(data.getString("cookie"));
//             }
//         } catch (JSONException e) {
//             throw new AuthenticationException("Could not parse login response.", e);
//         }
//     }
// 
//     public String getModHash() {
//         return modHash;
//     }
// 
//     public void setModHash(String modHash) {
//         this.modHash = modHash;
//     }
// 
//     public String getCookie() {
//         return cookie;
//     }
// 
//     public void setCookie(String cookie) {
//         this.cookie = cookie;
//     }
// 
//     public List<List<String>> getErrors() {
//         return errors;
//     }
// 
//     public void setErrors(List<List<String>> errors) {
//         this.errors = errors;
//     }
// }


// Path: tests/src/com/pocketreddit/library/authentication/TestLoginResult.java
import com.pocketreddit.library.authentication.LoginResult;
import android.test.AndroidTestCase;
import android.util.Log;

package com.pocketreddit.library.authentication;



public class TestLoginResult extends AndroidTestCase {
    private static final String TAG = TestLoginResult.class.getName();

    private final String successfulLoginJson = "{\"json\": {\"errors\": [], \"data\": {\"modhash\": \"7l7jf0fzvt9556d747b9ef00409e1a90d2fbdc328cd26b599b\", \"cookie\": \"13829964,2012-07-05T10:56:57,3acfec8427be44b0b90970d59a56e1b50ff74adf\"}}}";
    private final String badPasswordJson = "{\"json\": {\"errors\": [[\"WRONG_PASSWORD\", \"invalid password\", \"passwd\"]]}}";

    public void testLoginResultFromSuccess() {
        try {
            LoginResult login = new LoginResult(successfulLoginJson);
            assertTrue("LoginResult shouldn't produce any errors.", login.getErrors().isEmpty());
        } catch (Exception e) {
            Log.e(TAG, "Failed parsing login response.", e);
            fail("Failed parsing login response.");
        }
    }

    public void testLoginResultBadPw() {
        try {
            LoginResult login = new LoginResult(badPasswordJson);