### Question:
AdaptationExecutor { public static Result execute(List<AdaptationCommand> cmds) { Result result = new Result(); for (AdaptationCommand cmd : cmds) { try { cmd.execute(); result.executedCmds.add(cmd); } catch (KevoreeAdaptationException e) { result.error = e; return result; } } return result; }  static Result execute(List<AdaptationCommand> cmds); static List<KevoreeAdaptationException> forceExecute(List<AdaptationCommand> cmds); static void undo(List<AdaptationCommand> cmds);  }### Answer:
@Test public void emptyList() { List<AdaptationCommand> cmds = new ArrayList<>(); AdaptationExecutor.Result result = AdaptationExecutor.execute(cmds); Assert.assertTrue(result.getExecutedCmds().isEmpty()); }
@Test public void validCommandList() { List<AdaptationCommand> cmds = new ArrayList<>(); cmds.add(new ExecSuccessCmd()); cmds.add(new ExecSuccessCmd()); cmds.add(new ExecSuccessCmd()); AdaptationExecutor.Result result = AdaptationExecutor.execute(cmds); Assert.assertEquals(cmds.size(), result.getExecutedCmds().size()); Assert.assertNull(result.getError()); }
@Test public void invalidCommandList() { List<AdaptationCommand> cmds = new ArrayList<>(); AdaptationCommand successCommand = new ExecSuccessCmd(); cmds.add(successCommand); cmds.add(new ExecFailCmd()); cmds.add(new ExecSuccessCmd()); AdaptationExecutor.Result result = AdaptationExecutor.execute(cmds); Assert.assertEquals(1, result.getExecutedCmds().size()); Assert.assertEquals(successCommand, result.getExecutedCmds().iterator().next()); Assert.assertNotNull(result.getError()); }
@Test public void complexInvalidCommandList() { List<AdaptationCommand> cmds = new ArrayList<>(); AdaptationCommand ok0 = new ExecSuccessCmd(); AdaptationCommand ok1 = new ExecSuccessCmd(); AdaptationCommand ok2 = new ExecSuccessCmd(); cmds.add(ok0); cmds.add(ok1); cmds.add(ok2); cmds.add(new ExecFailCmd()); cmds.add(new ExecSuccessCmd()); AdaptationExecutor.Result result = AdaptationExecutor.execute(cmds); Assert.assertEquals(3, result.getExecutedCmds().size()); Iterator<AdaptationCommand> it = result.getExecutedCmds().iterator(); Assert.assertEquals(ok0, it.next()); Assert.assertEquals(ok1, it.next()); Assert.assertEquals(ok2, it.next()); Assert.assertNotNull(result.getError()); }