// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/exceptions/AlreadyExecutingException.java
// public class AlreadyExecutingException extends RuntimeException{
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnListResponseListener.java
// public interface OnListResponseListener<T> {
// 
//     void onResponse(int code, List<T> object, Response fullResponse);
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnObjResponseListener.java
// public interface OnObjResponseListener<T> {
// 
//     void onResponse(int code, T object, Response fullResponse);
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnResponseListener.java
// public interface OnResponseListener {
// 
//     void onResponse(int code, Response fullResponse, Exception e);
// 
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnTimeoutListener.java
// public interface OnTimeoutListener {
//     void onTimeout();
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncBlockRunner.java
// public interface AsyncBlockRunner {
// 
//     void run( AsyncTimeoutHelper asyncTimeoutHelper ) throws Exception;
// 
//     void onEndCalled( );
// 
//     void onTimeout( );
// 
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncTimeoutHelper.java
// public class AsyncTimeoutHelper {
// 
//     private final int timeoutMilis;
//     private final AsyncBlockRunner asyncBlockRunner;
// 
//     private final CountDownLatch latch = new CountDownLatch(1);
//     private String failMessage;
//     private Runnable assertions;
// 
//     private AsyncTimeoutHelper(int timeoutMilis, AsyncBlockRunner asyncBlockRunner){
//         this.timeoutMilis = timeoutMilis;
//         this.asyncBlockRunner = asyncBlockRunner;
//     }
// 
//     public static void runAndWaitForEnd(AndroidTestCase testCase, int timeoutMilis, AsyncBlockRunner asyncBlockRunner) throws Exception {
// 
//         new AsyncTimeoutHelper(timeoutMilis,asyncBlockRunner).run();
//     }
// 
//     private void run() throws Exception {
//         asyncBlockRunner.run(this);
// 
//         if(latch.await(timeoutMilis, TimeUnit.MILLISECONDS)){
//             if(failMessage==null) {
//                 if(assertions!=null){
//                     assertions.run();
//                 }
//                 asyncBlockRunner.onEndCalled();
//             }
//             else{
//                 AndroidTestCase.fail(failMessage);
//             }
//         }
//         else {
//             asyncBlockRunner.onTimeout();
//         }
//     }
// 
//     public void end(){
//         latch.countDown();
//     }
// 
//     public void failSync(String failMessage){
//         this.failMessage = failMessage;
// 
//         latch.countDown();
//     }
// 
//     public void performAssertions(Runnable runnable){
//         this.assertions = runnable;
//     }
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncTimeoutHelper.java
// public static void runAndWaitForEnd(AndroidTestCase testCase, int timeoutMilis, AsyncBlockRunner asyncBlockRunner) throws Exception {
// 
//     new AsyncTimeoutHelper(timeoutMilis,asyncBlockRunner).run();
// }


import com.greengrowapps.ggarest.exceptions.AlreadyExecutingException;
import com.greengrowapps.ggarest.listeners.OnListResponseListener;
import com.greengrowapps.ggarest.listeners.OnObjResponseListener;
import com.greengrowapps.ggarest.listeners.OnResponseListener;
import com.greengrowapps.ggarest.listeners.OnTimeoutListener;
import com.greengrowapps.ggarest.tools.AsyncBlockRunner;
import com.greengrowapps.ggarest.tools.AsyncTimeoutHelper;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
import static com.greengrowapps.ggarest.tools.AsyncTimeoutHelper.runAndWaitForEnd;
package com.greengrowapps.ggarest;





public class MockTest extends GgaRestTest {

    private static final int CONNECTION_TIMEOUT = 30*1000;

    public void testMockGet() throws Exception {

        final Webservice ws = getWebserviceInstance();
        ws.mockGet("http://www.google.com")
                .responseCode(204)
                .responseContent("{\"text\":\"hello\"}")
                .save();


        runAndWaitForEnd(this,CONNECTION_TIMEOUT, new AsyncBlockRunner() {

            @Override
            public void run(final AsyncTimeoutHelper asyncTimeoutHelper) throws AlreadyExecutingException {

                ws
                        .get("http://www.google.com")
                        .onResponse(SimpleObj.class, 204, new OnObjResponseListener<SimpleObj>() {
                            @Override
                            public void onResponse(int code, SimpleObj object, Response fullResponse) {
                                assertEquals(204,code);
                                assertEquals("hello",object.text);
                                asyncTimeoutHelper.end();
                            }
                        }).execute();
            }

            @Override
            public void onEndCalled() {
                //Success
            }

// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/exceptions/AlreadyExecutingException.java
// public class AlreadyExecutingException extends RuntimeException{
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnListResponseListener.java
// public interface OnListResponseListener<T> {
// 
//     void onResponse(int code, List<T> object, Response fullResponse);
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnObjResponseListener.java
// public interface OnObjResponseListener<T> {
// 
//     void onResponse(int code, T object, Response fullResponse);
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnResponseListener.java
// public interface OnResponseListener {
// 
//     void onResponse(int code, Response fullResponse, Exception e);
// 
// }
// 
// Path: GgaRestJavaLib/ggarest/src/main/java/com/greengrowapps/ggarest/listeners/OnTimeoutListener.java
// public interface OnTimeoutListener {
//     void onTimeout();
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncBlockRunner.java
// public interface AsyncBlockRunner {
// 
//     void run( AsyncTimeoutHelper asyncTimeoutHelper ) throws Exception;
// 
//     void onEndCalled( );
// 
//     void onTimeout( );
// 
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncTimeoutHelper.java
// public class AsyncTimeoutHelper {
// 
//     private final int timeoutMilis;
//     private final AsyncBlockRunner asyncBlockRunner;
// 
//     private final CountDownLatch latch = new CountDownLatch(1);
//     private String failMessage;
//     private Runnable assertions;
// 
//     private AsyncTimeoutHelper(int timeoutMilis, AsyncBlockRunner asyncBlockRunner){
//         this.timeoutMilis = timeoutMilis;
//         this.asyncBlockRunner = asyncBlockRunner;
//     }
// 
//     public static void runAndWaitForEnd(AndroidTestCase testCase, int timeoutMilis, AsyncBlockRunner asyncBlockRunner) throws Exception {
// 
//         new AsyncTimeoutHelper(timeoutMilis,asyncBlockRunner).run();
//     }
// 
//     private void run() throws Exception {
//         asyncBlockRunner.run(this);
// 
//         if(latch.await(timeoutMilis, TimeUnit.MILLISECONDS)){
//             if(failMessage==null) {
//                 if(assertions!=null){
//                     assertions.run();
//                 }
//                 asyncBlockRunner.onEndCalled();
//             }
//             else{
//                 AndroidTestCase.fail(failMessage);
//             }
//         }
//         else {
//             asyncBlockRunner.onTimeout();
//         }
//     }
// 
//     public void end(){
//         latch.countDown();
//     }
// 
//     public void failSync(String failMessage){
//         this.failMessage = failMessage;
// 
//         latch.countDown();
//     }
// 
//     public void performAssertions(Runnable runnable){
//         this.assertions = runnable;
//     }
// }
// 
// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/tools/AsyncTimeoutHelper.java
// public static void runAndWaitForEnd(AndroidTestCase testCase, int timeoutMilis, AsyncBlockRunner asyncBlockRunner) throws Exception {
// 
//     new AsyncTimeoutHelper(timeoutMilis,asyncBlockRunner).run();
// }


// Path: GgaRestAndroidLib/ggarest/src/androidTest/java/com/greengrowapps/ggarest/MockTest.java
import com.greengrowapps.ggarest.exceptions.AlreadyExecutingException;
import com.greengrowapps.ggarest.listeners.OnListResponseListener;
import com.greengrowapps.ggarest.listeners.OnObjResponseListener;
import com.greengrowapps.ggarest.listeners.OnResponseListener;
import com.greengrowapps.ggarest.listeners.OnTimeoutListener;
import com.greengrowapps.ggarest.tools.AsyncBlockRunner;
import com.greengrowapps.ggarest.tools.AsyncTimeoutHelper;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
import static com.greengrowapps.ggarest.tools.AsyncTimeoutHelper.runAndWaitForEnd;

package com.greengrowapps.ggarest;





public class MockTest extends GgaRestTest {

    private static final int CONNECTION_TIMEOUT = 30*1000;

    public void testMockGet() throws Exception {

        final Webservice ws = getWebserviceInstance();
        ws.mockGet("http://www.google.com")
                .responseCode(204)
                .responseContent("{\"text\":\"hello\"}")
                .save();


        runAndWaitForEnd(this,CONNECTION_TIMEOUT, new AsyncBlockRunner() {

            @Override
            public void run(final AsyncTimeoutHelper asyncTimeoutHelper) throws AlreadyExecutingException {

                ws
                        .get("http://www.google.com")
                        .onResponse(SimpleObj.class, 204, new OnObjResponseListener<SimpleObj>() {
                            @Override
                            public void onResponse(int code, SimpleObj object, Response fullResponse) {
                                assertEquals(204,code);
                                assertEquals("hello",object.text);
                                asyncTimeoutHelper.end();
                            }
                        }).execute();
            }

            @Override
            public void onEndCalled() {
                //Success
            }

            @Override