// Path: stage/src/test/java/com/hippo/stage/util/ActivityProxy.java
// public class ActivityProxy {
// 
//   private Bundle savedInstanceState;
//   private boolean isCreated;
//   private boolean isStarted;
//   private boolean isResumed;
// 
//   private ActivityController<TestActivity> controller;
// 
//   public ActivityProxy() {
//     controller = Robolectric.buildActivity(TestActivity.class);
//   }
// 
//   public TestActivity get() {
//     return controller.get();
//   }
// 
//   public ActivityProxy create() {
//     if (isCreated) {
//       throw new IllegalStateException("The activity is already created");
//     }
//     isCreated = true;
//     controller.create(savedInstanceState);
//     return this;
//   }
// 
//   public ActivityProxy start() {
//     if (isStarted) {
//       throw new IllegalStateException("The activity is already started");
//     }
//     isStarted = true;
//     controller.start();
//     return this;
//   }
// 
//   public ActivityProxy resume() {
//     if (isResumed) {
//       throw new IllegalStateException("The activity is already resumed");
//     }
//     isResumed = true;
//     controller.resume();
//     return this;
//   }
// 
//   public ActivityProxy pause() {
//     if (!isResumed) {
//       throw new IllegalStateException("The activity isn't resumed");
//     }
//     isResumed = false;
//     controller.pause();
//     return this;
//   }
// 
//   public ActivityProxy stop() {
//     if (!isStarted) {
//       throw new IllegalStateException("The activity isn't started");
//     }
//     isStarted = false;
//     controller.stop();
//     return this;
//   }
// 
//   public ActivityProxy destroy() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
//     isCreated = false;
//     controller.destroy();
//     return this;
//   }
// 
//   public void finish() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
//     get().finish();
//     if (isResumed) {
//       pause();
//     }
//     if (isStarted) {
//       stop();
//     }
//     destroy();
//   }
// 
//   public ActivityProxy restoreFromSavedState() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
// 
//     savedInstanceState = new Bundle();
//     controller.saveInstanceState(savedInstanceState);
// 
//     if (isResumed) {
//       pause();
//     }
//     if (isStarted) {
//       stop();
//     }
//     destroy();
// 
//     controller = Robolectric.buildActivity(TestActivity.class);
// 
//     create();
// 
//     return this;
//   }
// }
// 
// Path: stage/src/test/java/com/hippo/stage/util/TestContainer.java
// public class TestContainer extends FrameLayout {
// 
//   public TestContainer(@NonNull Context context) {
//     super(context);
//   }
// 
//   public TestContainer(@NonNull Context context,
//       @Nullable AttributeSet attrs) {
//     super(context, attrs);
//   }
// 
//   public TestContainer(@NonNull Context context,
//       @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
//     super(context, attrs, defStyleAttr);
//   }
// 
//   /**
//    * @param ids from top to root
//    */
//   public void assertChildren(int... ids) {
//     assertEquals(ids.length, getChildCount());
// 
//     int index = ids.length;
//     while (--index >= 0) {
//       assertEquals("index of child = " + index, ids[index], getChildAt(index).getId());
//     }
//   }
// }


import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.annotation.IdRes;
import android.view.ViewGroup;
import com.hippo.stage.util.ActivityProxy;
import com.hippo.stage.util.TestContainer;
import org.junit.Before;
import org.junit.Test;

    stage.close();

    assertEquals(true, scene1.getLifecycleState().hasDestroyed());
    assertEquals(true, scene2.getLifecycleState().hasDestroyed());
    assertEquals(0, container.getChildCount());
  }

  @Test
  public void testHeadlessStage() {
    director.start();
    director.resume();

    Stage stage = director.direct(1);

    Scene scene1 = new TestScene();
    Scene scene2 = new TestScene();

    stage.pushScene(scene1);
    stage.pushScene(scene2);

    assertFalse(scene2.getLifecycleState().isViewAttached());

    stage.restore(new TestContainer(RuntimeEnvironment.application));

    assertTrue(scene2.getLifecycleState().isViewAttached());
  }

  @Test
  public void testSaveDisabled() {
// Path: stage/src/test/java/com/hippo/stage/util/ActivityProxy.java
// public class ActivityProxy {
// 
//   private Bundle savedInstanceState;
//   private boolean isCreated;
//   private boolean isStarted;
//   private boolean isResumed;
// 
//   private ActivityController<TestActivity> controller;
// 
//   public ActivityProxy() {
//     controller = Robolectric.buildActivity(TestActivity.class);
//   }
// 
//   public TestActivity get() {
//     return controller.get();
//   }
// 
//   public ActivityProxy create() {
//     if (isCreated) {
//       throw new IllegalStateException("The activity is already created");
//     }
//     isCreated = true;
//     controller.create(savedInstanceState);
//     return this;
//   }
// 
//   public ActivityProxy start() {
//     if (isStarted) {
//       throw new IllegalStateException("The activity is already started");
//     }
//     isStarted = true;
//     controller.start();
//     return this;
//   }
// 
//   public ActivityProxy resume() {
//     if (isResumed) {
//       throw new IllegalStateException("The activity is already resumed");
//     }
//     isResumed = true;
//     controller.resume();
//     return this;
//   }
// 
//   public ActivityProxy pause() {
//     if (!isResumed) {
//       throw new IllegalStateException("The activity isn't resumed");
//     }
//     isResumed = false;
//     controller.pause();
//     return this;
//   }
// 
//   public ActivityProxy stop() {
//     if (!isStarted) {
//       throw new IllegalStateException("The activity isn't started");
//     }
//     isStarted = false;
//     controller.stop();
//     return this;
//   }
// 
//   public ActivityProxy destroy() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
//     isCreated = false;
//     controller.destroy();
//     return this;
//   }
// 
//   public void finish() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
//     get().finish();
//     if (isResumed) {
//       pause();
//     }
//     if (isStarted) {
//       stop();
//     }
//     destroy();
//   }
// 
//   public ActivityProxy restoreFromSavedState() {
//     if (!isCreated) {
//       throw new IllegalStateException("The activity isn't created");
//     }
// 
//     savedInstanceState = new Bundle();
//     controller.saveInstanceState(savedInstanceState);
// 
//     if (isResumed) {
//       pause();
//     }
//     if (isStarted) {
//       stop();
//     }
//     destroy();
// 
//     controller = Robolectric.buildActivity(TestActivity.class);
// 
//     create();
// 
//     return this;
//   }
// }
// 
// Path: stage/src/test/java/com/hippo/stage/util/TestContainer.java
// public class TestContainer extends FrameLayout {
// 
//   public TestContainer(@NonNull Context context) {
//     super(context);
//   }
// 
//   public TestContainer(@NonNull Context context,
//       @Nullable AttributeSet attrs) {
//     super(context, attrs);
//   }
// 
//   public TestContainer(@NonNull Context context,
//       @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
//     super(context, attrs, defStyleAttr);
//   }
// 
//   /**
//    * @param ids from top to root
//    */
//   public void assertChildren(int... ids) {
//     assertEquals(ids.length, getChildCount());
// 
//     int index = ids.length;
//     while (--index >= 0) {
//       assertEquals("index of child = " + index, ids[index], getChildAt(index).getId());
//     }
//   }
// }


// Path: stage/src/test/java/com/hippo/stage/DirectorTest.java
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.support.annotation.IdRes;
import android.view.ViewGroup;
import com.hippo.stage.util.ActivityProxy;
import com.hippo.stage.util.TestContainer;
import org.junit.Before;
import org.junit.Test;


    stage.close();

    assertEquals(true, scene1.getLifecycleState().hasDestroyed());
    assertEquals(true, scene2.getLifecycleState().hasDestroyed());
    assertEquals(0, container.getChildCount());
  }

  @Test
  public void testHeadlessStage() {
    director.start();
    director.resume();

    Stage stage = director.direct(1);

    Scene scene1 = new TestScene();
    Scene scene2 = new TestScene();

    stage.pushScene(scene1);
    stage.pushScene(scene2);

    assertFalse(scene2.getLifecycleState().isViewAttached());

    stage.restore(new TestContainer(RuntimeEnvironment.application));

    assertTrue(scene2.getLifecycleState().isViewAttached());
  }

  @Test
  public void testSaveDisabled() {
    ActivityProxy proxy = new ActivityProxy();