// Path: androidunittest/src/main/java/com/github/florent37/androidunittest/controllers/ControllerActivity.java
// public class ControllerActivity {
// 
//     private AndroidUnitTest androidUnitTest;
// 
//     public ControllerActivity(AndroidUnitTest androidUnitTest) {
//         this.androidUnitTest = androidUnitTest;
//     }
// 
//     @Nullable
//     public Activity get() {
//         if (androidUnitTest.getActivityController() != null) {
//             return (Activity) androidUnitTest.getActivityController().get();
//         }
//         return null;
//     }
// 
//     @Nullable
//     public ActivityController getActivityController() {
//         if (androidUnitTest.getActivityController() != null) {
//             return androidUnitTest.getActivityController();
//         }
//         return null;
//     }
// 
//     public Activity createAndInitActivity(Class activityClass, @Nullable RActivity activityAnnotation) {
//         ActivityController activityController = ActivityController.of(Robolectric.getShadowsAdapter(), activityClass);
//         androidUnitTest.setActivityController(activityController);
//         if (activityAnnotation != null) {
//             ActivityState activityState = activityAnnotation.state();
//             setActivityState(activityController, activityState);
//         }
//         Activity activity = (Activity) activityController.get();
//         return Mockito.spy(activity);
//     }
// 
//     public ControllerActivity resume() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().resume();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity create() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().create();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity start() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().start();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity pause() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().pause();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity stop() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().stop();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity destroy() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().destroy();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity setActivityState(ActivityState activityState) {
//         if (androidUnitTest.getActivityController() != null) {
//             setActivityState(getActivityController(), activityState);
//         }
//         return this;
//     }
// 
//     public ControllerActivity setActivityState(ActivityController activityController, ActivityState activityState) {
//         ActivityState init = ActivityState.CREATED;
// 
//         while (init != null && init.isLowerOrEquals(activityState)) {
//             System.out.println(init);
//             applyState(init, activityController);
//             init = init.next();
//         }
// 
//         return this;
//     }
// 
//     private void applyState(ActivityState state,
//                             ActivityController controller) {
//         switch (state) {
//             case STARTED:
//                 controller.start();
//                 break;
//             case RESUMED:
//                 controller.resume();
//                 break;
//             case PAUSED:
//                 controller.pause();
//                 break;
//             case STOPPED:
//                 controller.stop();
//                 break;
//             case DESTROYED:
//                 controller.destroy();
//                 break;
//             case CREATED:
//             default:
//                 controller.create();
//                 break;
//         }
//     }
// 
// }
// 
// Path: androidunittest/src/main/java/com/github/florent37/androidunittest/controllers/ControllerFragment.java
// public class ControllerFragment {
//     private AndroidUnitTest androidUnitTest;
//     public ControllerFragment(AndroidUnitTest androidUnitTest) {
//         this.androidUnitTest = androidUnitTest;
//     }
// 
//     public ControllerFragment attachToActivity(Fragment fragment){
//         if (androidUnitTest.activity().get() == null) {
// 
//         }
//         androidUnitTest.getAndroidUnitTestAnnotations().addToActivity(fragment);
//         return this;
//     }
// 
//     public ControllerFragment removeFromActivity(Fragment fragment){
//         androidUnitTest.getAndroidUnitTestAnnotations().removeFromActivity(fragment);
//         return this;
//     }
// }


import android.support.annotation.Nullable;
import com.github.florent37.androidunittest.controllers.ControllerActivity;
import com.github.florent37.androidunittest.controllers.ControllerFragment;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.util.ActivityController;
package com.github.florent37.androidunittest;




/**
 * Created by florentchampigny on 07/05/2016.
 */
public class AndroidUnitTest implements MethodRule {

    ControllerActivity controllerActivity;
    ControllerFragment controllerFragment;
    @Nullable ActivityController activityController;
    private AndroidUnitTestAnnotations androidUnitTestAnnotations;

    protected AndroidUnitTest() {
        androidUnitTestAnnotations = new AndroidUnitTestAnnotations(AndroidUnitTest.this);
// Path: androidunittest/src/main/java/com/github/florent37/androidunittest/controllers/ControllerActivity.java
// public class ControllerActivity {
// 
//     private AndroidUnitTest androidUnitTest;
// 
//     public ControllerActivity(AndroidUnitTest androidUnitTest) {
//         this.androidUnitTest = androidUnitTest;
//     }
// 
//     @Nullable
//     public Activity get() {
//         if (androidUnitTest.getActivityController() != null) {
//             return (Activity) androidUnitTest.getActivityController().get();
//         }
//         return null;
//     }
// 
//     @Nullable
//     public ActivityController getActivityController() {
//         if (androidUnitTest.getActivityController() != null) {
//             return androidUnitTest.getActivityController();
//         }
//         return null;
//     }
// 
//     public Activity createAndInitActivity(Class activityClass, @Nullable RActivity activityAnnotation) {
//         ActivityController activityController = ActivityController.of(Robolectric.getShadowsAdapter(), activityClass);
//         androidUnitTest.setActivityController(activityController);
//         if (activityAnnotation != null) {
//             ActivityState activityState = activityAnnotation.state();
//             setActivityState(activityController, activityState);
//         }
//         Activity activity = (Activity) activityController.get();
//         return Mockito.spy(activity);
//     }
// 
//     public ControllerActivity resume() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().resume();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity create() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().create();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity start() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().start();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity pause() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().pause();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity stop() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().stop();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity destroy() {
//         if (androidUnitTest.getActivityController() != null) {
//             androidUnitTest.getActivityController().destroy();
//             androidUnitTest.getAndroidUnitTestAnnotations().updateActivity();
//         }
//         return this;
//     }
// 
//     public ControllerActivity setActivityState(ActivityState activityState) {
//         if (androidUnitTest.getActivityController() != null) {
//             setActivityState(getActivityController(), activityState);
//         }
//         return this;
//     }
// 
//     public ControllerActivity setActivityState(ActivityController activityController, ActivityState activityState) {
//         ActivityState init = ActivityState.CREATED;
// 
//         while (init != null && init.isLowerOrEquals(activityState)) {
//             System.out.println(init);
//             applyState(init, activityController);
//             init = init.next();
//         }
// 
//         return this;
//     }
// 
//     private void applyState(ActivityState state,
//                             ActivityController controller) {
//         switch (state) {
//             case STARTED:
//                 controller.start();
//                 break;
//             case RESUMED:
//                 controller.resume();
//                 break;
//             case PAUSED:
//                 controller.pause();
//                 break;
//             case STOPPED:
//                 controller.stop();
//                 break;
//             case DESTROYED:
//                 controller.destroy();
//                 break;
//             case CREATED:
//             default:
//                 controller.create();
//                 break;
//         }
//     }
// 
// }
// 
// Path: androidunittest/src/main/java/com/github/florent37/androidunittest/controllers/ControllerFragment.java
// public class ControllerFragment {
//     private AndroidUnitTest androidUnitTest;
//     public ControllerFragment(AndroidUnitTest androidUnitTest) {
//         this.androidUnitTest = androidUnitTest;
//     }
// 
//     public ControllerFragment attachToActivity(Fragment fragment){
//         if (androidUnitTest.activity().get() == null) {
// 
//         }
//         androidUnitTest.getAndroidUnitTestAnnotations().addToActivity(fragment);
//         return this;
//     }
// 
//     public ControllerFragment removeFromActivity(Fragment fragment){
//         androidUnitTest.getAndroidUnitTestAnnotations().removeFromActivity(fragment);
//         return this;
//     }
// }


// Path: androidunittest/src/main/java/com/github/florent37/androidunittest/AndroidUnitTest.java
import android.support.annotation.Nullable;
import com.github.florent37.androidunittest.controllers.ControllerActivity;
import com.github.florent37.androidunittest.controllers.ControllerFragment;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.util.ActivityController;

package com.github.florent37.androidunittest;




/**
 * Created by florentchampigny on 07/05/2016.
 */
public class AndroidUnitTest implements MethodRule {

    ControllerActivity controllerActivity;
    ControllerFragment controllerFragment;
    @Nullable ActivityController activityController;
    private AndroidUnitTestAnnotations androidUnitTestAnnotations;

    protected AndroidUnitTest() {
        androidUnitTestAnnotations = new AndroidUnitTestAnnotations(AndroidUnitTest.this);
        controllerActivity = new ControllerActivity(this);