// Path: sdk/src/com/sharethis/loopy/sdk/net/HttpClientFactory.java
// public class HttpClientFactory {
// 
//     public static final int DEFAULT_CONNECTION_TIMEOUT = 1000;
//     public static final int DEFAULT_READ_TIMEOUT = 1000;
// 
//     private HttpParams params;
//     private ClientConnectionManager connectionManager;
//     private DefaultHttpClient client; // This should be thread safe
//     private IdleConnectionMonitorThread monitor;
//     private boolean initialized = false;
// 
//     private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
//     private int readTimeout = DEFAULT_READ_TIMEOUT;
// 
//     public void start(int timeout) {
//         setConnectionTimeout(timeout);
//         setReadTimeout(timeout);
//         init();
//     }
// 
//     public void stop() {
//         destroy();
//     }
// 
//     void init()  {
//         if(!initialized) {
// 
//             params = new BasicHttpParams();
// 
//             HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
//             HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
//             HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
//             HttpConnectionParams.setSoTimeout(params, readTimeout);
// 
//             SchemeRegistry registry = new SchemeRegistry();
//             registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
//             registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// 
//             connectionManager = new ThreadSafeClientConnManager(params, registry);
// 
//             monitor = new IdleConnectionMonitorThread(connectionManager);
//             monitor.setDaemon(true);
//             monitor.start();
//         }
//     }
// 
//     void destroy() {
//         if(initialized) {
//             initialized = false;
//             if(monitor != null) {
//                 monitor.shutdown();
//             }
//             if(connectionManager != null) {
//                 connectionManager.shutdown();
//             }
//         }
//     }
// 
//     public synchronized HttpClient getClient() {
//         if(client == null) {
//             client = new DefaultHttpClient(connectionManager, params);
//         }
//         else {
//             monitor.trigger();
//         }
// 
//         return client;
//     }
// 
//     public int getConnectionTimeout() {
//         return connectionTimeout;
//     }
// 
//     public void setConnectionTimeout(int connectionTimeout) {
//         this.connectionTimeout = connectionTimeout;
//     }
// 
//     public int getReadTimeout() {
//         return readTimeout;
//     }
// 
//     public void setReadTimeout(int readTimeout) {
//         this.readTimeout = readTimeout;
//     }
// }
// 
// Path: test/src/com/sharethis/loopy/test/util/Holder.java
// public class Holder<T> {
// 
// 	private T object;
// 
//     private List<T> objects = new ArrayList<T>();
// 
// 	public Holder() {}
// 
// 	public Holder(T object) {
// 		super();
// 		this.object = object;
// 	}
// 
// 	public T get() {
// 		return object;
// 	}
// 
// 	public void set(T object) {
// 		this.object = object;
// 	}
// 
//     public void add(T object) {
//         objects.add(object);
//     }
// 
//     public List<T> getObjects() {
//         return objects;
//     }
// }


import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.sharethis.loopy.sdk.*;
import com.sharethis.loopy.sdk.net.HttpClientFactory;
import com.sharethis.loopy.test.util.Holder;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.mockito.Mockito;
/*
 *
 *  * Copyright (c) 2013 ShareThis Inc.
 *  *
 *  * Permission is hereby granted, free of charge, to any person obtaining a copy
 *  * of this software and associated documentation files (the "Software"), to deal
 *  * in the Software without restriction, including without limitation the rights
 *  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  * copies of the Software, and to permit persons to whom the Software is
 *  * furnished to do so, subject to the following conditions:
 *  *
 *  * The above copyright notice and this permission notice shall be included in
 *  * all copies or substantial portions of the Software.
 *  *
 *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  * THE SOFTWARE.
 *
 */

package com.sharethis.loopy.test;



/**
 * @author Jason Polites
 */
public class NetworkStateTest extends LoopyAndroidTestCase {
    @Override
    public void setUp() throws Exception {
        super.setUp();
        Loopy.onStart(getContext());
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        Loopy.onStop(getContext());
    }

    // Not a REAL test, but we can't test network because disabling network on device kills adb.
    public void testShortenReturnsWhenNoNetwork() throws InterruptedException, IOException {

        Session.getInstance().waitForStart();

        final String url = "foobar";
        final Holder<Item> result = new Holder<Item>();
        final Holder<Throwable> resultThrowable = new Holder<Throwable>();
        final CountDownLatch latch = new CountDownLatch(1);

// Path: sdk/src/com/sharethis/loopy/sdk/net/HttpClientFactory.java
// public class HttpClientFactory {
// 
//     public static final int DEFAULT_CONNECTION_TIMEOUT = 1000;
//     public static final int DEFAULT_READ_TIMEOUT = 1000;
// 
//     private HttpParams params;
//     private ClientConnectionManager connectionManager;
//     private DefaultHttpClient client; // This should be thread safe
//     private IdleConnectionMonitorThread monitor;
//     private boolean initialized = false;
// 
//     private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
//     private int readTimeout = DEFAULT_READ_TIMEOUT;
// 
//     public void start(int timeout) {
//         setConnectionTimeout(timeout);
//         setReadTimeout(timeout);
//         init();
//     }
// 
//     public void stop() {
//         destroy();
//     }
// 
//     void init()  {
//         if(!initialized) {
// 
//             params = new BasicHttpParams();
// 
//             HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
//             HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
//             HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
//             HttpConnectionParams.setSoTimeout(params, readTimeout);
// 
//             SchemeRegistry registry = new SchemeRegistry();
//             registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
//             registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
// 
//             connectionManager = new ThreadSafeClientConnManager(params, registry);
// 
//             monitor = new IdleConnectionMonitorThread(connectionManager);
//             monitor.setDaemon(true);
//             monitor.start();
//         }
//     }
// 
//     void destroy() {
//         if(initialized) {
//             initialized = false;
//             if(monitor != null) {
//                 monitor.shutdown();
//             }
//             if(connectionManager != null) {
//                 connectionManager.shutdown();
//             }
//         }
//     }
// 
//     public synchronized HttpClient getClient() {
//         if(client == null) {
//             client = new DefaultHttpClient(connectionManager, params);
//         }
//         else {
//             monitor.trigger();
//         }
// 
//         return client;
//     }
// 
//     public int getConnectionTimeout() {
//         return connectionTimeout;
//     }
// 
//     public void setConnectionTimeout(int connectionTimeout) {
//         this.connectionTimeout = connectionTimeout;
//     }
// 
//     public int getReadTimeout() {
//         return readTimeout;
//     }
// 
//     public void setReadTimeout(int readTimeout) {
//         this.readTimeout = readTimeout;
//     }
// }
// 
// Path: test/src/com/sharethis/loopy/test/util/Holder.java
// public class Holder<T> {
// 
// 	private T object;
// 
//     private List<T> objects = new ArrayList<T>();
// 
// 	public Holder() {}
// 
// 	public Holder(T object) {
// 		super();
// 		this.object = object;
// 	}
// 
// 	public T get() {
// 		return object;
// 	}
// 
// 	public void set(T object) {
// 		this.object = object;
// 	}
// 
//     public void add(T object) {
//         objects.add(object);
//     }
// 
//     public List<T> getObjects() {
//         return objects;
//     }
// }


// Path: test/src/com/sharethis/loopy/test/NetworkStateTest.java
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.sharethis.loopy.sdk.*;
import com.sharethis.loopy.sdk.net.HttpClientFactory;
import com.sharethis.loopy.test.util.Holder;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.mockito.Mockito;

/*
 *
 *  * Copyright (c) 2013 ShareThis Inc.
 *  *
 *  * Permission is hereby granted, free of charge, to any person obtaining a copy
 *  * of this software and associated documentation files (the "Software"), to deal
 *  * in the Software without restriction, including without limitation the rights
 *  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  * copies of the Software, and to permit persons to whom the Software is
 *  * furnished to do so, subject to the following conditions:
 *  *
 *  * The above copyright notice and this permission notice shall be included in
 *  * all copies or substantial portions of the Software.
 *  *
 *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  * THE SOFTWARE.
 *
 */

package com.sharethis.loopy.test;



/**
 * @author Jason Polites
 */
public class NetworkStateTest extends LoopyAndroidTestCase {
    @Override
    public void setUp() throws Exception {
        super.setUp();
        Loopy.onStart(getContext());
    }

    @Override
    public void tearDown() throws Exception {
        super.tearDown();
        Loopy.onStop(getContext());
    }

    // Not a REAL test, but we can't test network because disabling network on device kills adb.
    public void testShortenReturnsWhenNoNetwork() throws InterruptedException, IOException {

        Session.getInstance().waitForStart();

        final String url = "foobar";
        final Holder<Item> result = new Holder<Item>();
        final Holder<Throwable> resultThrowable = new Holder<Throwable>();
        final CountDownLatch latch = new CountDownLatch(1);

        HttpClientFactory httpClientFactory = Mockito.mock(HttpClientFactory.class);