@Test
public void testSummaryTreeNodeState() throws Exception {

  //Nothing installed
  TestTreeNode n1 = new TestTreeNode(NOT_INSTALLED, false);
  n1.setIncludeInSummary(true);
  TestTreeNode n2 = new TestTreeNode(NOT_INSTALLED, false);
  n2.setIncludeInSummary(true);
  TestTreeNode n3 = new TestTreeNode(NOT_INSTALLED, false);
  ImmutableSet<UpdaterTreeNode> children = ImmutableSet.of(n1, n2, n3);
  SummaryTreeNode node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children);
  children.forEach(node::add);
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  // Included not installed
  n3 = new TestTreeNode(INSTALLED, false);
  children = ImmutableSet.of(n1, n2, n3);
  node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children);
  children.forEach(node::add);
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, INSTALLED));
  node.cycleState();
  validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, INSTALLED));
  node.cycleState();
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, INSTALLED));
  // Included installed but others not
  n1 = new TestTreeNode(INSTALLED, false);
  n1.setIncludeInSummary(true);
  n2 = new TestTreeNode(INSTALLED, false);
  n2.setIncludeInSummary(true);
  n3 = new TestTreeNode(NOT_INSTALLED, false);
  children = ImmutableSet.of(n1, n2, n3);
  node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children);
  children.forEach(node::add);
  validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, NOT_INSTALLED, INSTALLED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, INSTALLED, INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED));
  // Some included installed
  n2 = new TestTreeNode(NOT_INSTALLED, false);
  n2.setIncludeInSummary(true);
  children = ImmutableSet.of(n1, n2, n3);
  node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children);
  children.forEach(node::add);
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, NOT_INSTALLED, NOT_INSTALLED, ImmutableList.of(INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  // Included upgradable
  n2 = new TestTreeNode(MIXED, true);
  n2.setIncludeInSummary(true);
  children = ImmutableSet.of(n1, n2, n3);
  node = SummaryTreeNode.createNode(new AndroidVersion(17, null), children);
  children.forEach(node::add);
  validateState(node, MIXED, MIXED, ImmutableList.of(INSTALLED, MIXED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, INSTALLED, MIXED, ImmutableList.of(INSTALLED, INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, NOT_INSTALLED, MIXED, ImmutableList.of(NOT_INSTALLED, NOT_INSTALLED, NOT_INSTALLED));
  node.cycleState();
  validateState(node, MIXED, MIXED, ImmutableList.of(INSTALLED, MIXED, NOT_INSTALLED));
}