// Path: src/com/pocketreddit/library/authentication/AuthenticationException.java
// public class AuthenticationException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public AuthenticationException(String message) {
//         super(message);
//     }
//     
// 	public AuthenticationException(String message, Throwable throwable) {
// 		super(message, throwable);
// 	}
// }
// 
// Path: src/com/pocketreddit/library/authentication/LiveAuthenticator.java
// public class LiveAuthenticator implements Authenticator {
//     private static final String TAG = LiveAuthenticator.class.getName();
// 
//     private static final String LOGIN_URI = "https://ssl.reddit.com/api/login";
//     private static final String PARAM_USERNAME = "user";
//     private static final String PARAM_PASSWORD = "passwd";
// 
//     private static final String PARAM_API_TYPE = "api_type";
//     private static final String API_TYPE_JSON = "json";
// 
//     public LoginResult authenticate(String username, String password)
//             throws AuthenticationException {
//         try {
//             return new LoginResult(HttpHelper.getInstance().getJsonObjectFromPost(
//                     new URI(LOGIN_URI + "/" + username),
//                     nameValuePairs(PARAM_USERNAME, username, PARAM_PASSWORD, password,
//                             PARAM_API_TYPE, API_TYPE_JSON)));
//         } catch (Exception e) {
//             Log.e(TAG, "Unable to authenticate user: " + username, e);
//             throw new AuthenticationException("Unable to authenticate user: " + username, e);
//         }
//     }
// 
//     private List<NameValuePair> nameValuePairs(String... keysAndValues) {
//         if (keysAndValues.length % 2 != 0) {
//             throw new IllegalArgumentException("Must contain keys and values, length cannot be odd");
//         }
// 
//         List<NameValuePair> pairs = new ArrayList<NameValuePair>();
// 
//         for (int i = 0; i < keysAndValues.length; i += 2) {
//             pairs.add(new BasicNameValuePair(keysAndValues[i], keysAndValues[i + 1]));
//         }
// 
//         return pairs;
//     }
// }
// 
// 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.AuthenticationException;
import com.pocketreddit.library.authentication.LiveAuthenticator;
import com.pocketreddit.library.authentication.LoginResult;
import android.test.AndroidTestCase;
import android.util.Log;
package com.pocketreddit.library.authentication;



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

    public void testLoginWithBadPw() {
        LiveAuthenticator authenticator = new LiveAuthenticator();
        try {
            LoginResult result = authenticator.authenticate("testachan", "baddpw");
            assertFalse("LoginResult should produce errors when there is a bad pw.", result
                    .getErrors().isEmpty());
// Path: src/com/pocketreddit/library/authentication/AuthenticationException.java
// public class AuthenticationException extends Exception {
//     private static final long serialVersionUID = 1L;
// 
//     public AuthenticationException(String message) {
//         super(message);
//     }
//     
// 	public AuthenticationException(String message, Throwable throwable) {
// 		super(message, throwable);
// 	}
// }
// 
// Path: src/com/pocketreddit/library/authentication/LiveAuthenticator.java
// public class LiveAuthenticator implements Authenticator {
//     private static final String TAG = LiveAuthenticator.class.getName();
// 
//     private static final String LOGIN_URI = "https://ssl.reddit.com/api/login";
//     private static final String PARAM_USERNAME = "user";
//     private static final String PARAM_PASSWORD = "passwd";
// 
//     private static final String PARAM_API_TYPE = "api_type";
//     private static final String API_TYPE_JSON = "json";
// 
//     public LoginResult authenticate(String username, String password)
//             throws AuthenticationException {
//         try {
//             return new LoginResult(HttpHelper.getInstance().getJsonObjectFromPost(
//                     new URI(LOGIN_URI + "/" + username),
//                     nameValuePairs(PARAM_USERNAME, username, PARAM_PASSWORD, password,
//                             PARAM_API_TYPE, API_TYPE_JSON)));
//         } catch (Exception e) {
//             Log.e(TAG, "Unable to authenticate user: " + username, e);
//             throw new AuthenticationException("Unable to authenticate user: " + username, e);
//         }
//     }
// 
//     private List<NameValuePair> nameValuePairs(String... keysAndValues) {
//         if (keysAndValues.length % 2 != 0) {
//             throw new IllegalArgumentException("Must contain keys and values, length cannot be odd");
//         }
// 
//         List<NameValuePair> pairs = new ArrayList<NameValuePair>();
// 
//         for (int i = 0; i < keysAndValues.length; i += 2) {
//             pairs.add(new BasicNameValuePair(keysAndValues[i], keysAndValues[i + 1]));
//         }
// 
//         return pairs;
//     }
// }
// 
// 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/IntegrationLiveAuthenticationTest.java
import com.pocketreddit.library.authentication.AuthenticationException;
import com.pocketreddit.library.authentication.LiveAuthenticator;
import com.pocketreddit.library.authentication.LoginResult;
import android.test.AndroidTestCase;
import android.util.Log;

package com.pocketreddit.library.authentication;



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

    public void testLoginWithBadPw() {
        LiveAuthenticator authenticator = new LiveAuthenticator();
        try {
            LoginResult result = authenticator.authenticate("testachan", "baddpw");
            assertFalse("LoginResult should produce errors when there is a bad pw.", result
                    .getErrors().isEmpty());
        } catch (AuthenticationException e) {