MacrosIrDelayUtil { public static void ensureDelayForIrCommand(List<ExecutableCommand> commands){ List<Integer> irCmdIndex = getIrCommandIndexList(commands); if (irCmdIndex == null) { return; } long minDelaySeconds = ControllerConfiguration.readXML().getMacroIRExecutionDelay(); Map<Integer, DelayCommand> delays = getDelayForIrCommand(commands, irCmdIndex, minDelaySeconds); int addTimes = 0; Set<Integer> insertIndex = delays.keySet(); for (Integer index : insertIndex) { commands.add(index + addTimes, delays.get(index)); addTimes++; logger.info("add " + minDelaySeconds + " seconds before " + index + " ircommand"); } }  static void ensureDelayForIrCommand(List<ExecutableCommand> commands);  }
@Test public void testHaveNotOnlyIrcCmdAndDelayCmd() { MacrosIrDelayUtil.ensureDelayForIrCommand(haveNotIrCmd); Assert.assertTrue(haveNotIrCmd.size() == 5); }
@Test public void testContainOneOrNoDelayCmdBetweenTwoIrCmd() { MacrosIrDelayUtil.ensureDelayForIrCommand(containOneOrNoDelayCmdBetweenTwoIrCmd); Assert.assertTrue(containOneOrNoDelayCmdBetweenTwoIrCmd.size() == 7); Assert.assertTrue(containOneOrNoDelayCmdBetweenTwoIrCmd.get(0) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containOneOrNoDelayCmdBetweenTwoIrCmd.get(1)).getDelayMillisecond() == 200); Assert.assertTrue(((DelayCommand) containOneOrNoDelayCmdBetweenTwoIrCmd.get(2)).getDelayMillisecond() == 300); Assert.assertTrue(containOneOrNoDelayCmdBetweenTwoIrCmd.get(3) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containOneOrNoDelayCmdBetweenTwoIrCmd.get(4)).getDelayMillisecond() == 500); Assert.assertTrue(containOneOrNoDelayCmdBetweenTwoIrCmd.get(5) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containOneOrNoDelayCmdBetweenTwoIrCmd.get(6)).getDelayMillisecond() == 800); }
@Test public void testContainMultiDelayCmdBetweenTwoIrCmd() { MacrosIrDelayUtil.ensureDelayForIrCommand(containMultiDelayCmdBetweenTwoIrCmd); Assert.assertTrue(containMultiDelayCmdBetweenTwoIrCmd.size() == 11); Assert.assertTrue(containMultiDelayCmdBetweenTwoIrCmd.get(0) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(1)).getDelayMillisecond() == 200); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(2)).getDelayMillisecond() == 200); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(3)).getDelayMillisecond() == 100); Assert.assertTrue(containMultiDelayCmdBetweenTwoIrCmd.get(4) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(5)).getDelayMillisecond() == 200); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(6)).getDelayMillisecond() == 200); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(7)).getDelayMillisecond() == 200); Assert.assertTrue(containMultiDelayCmdBetweenTwoIrCmd.get(8) instanceof IRCommand); Assert.assertTrue(((DelayCommand) containMultiDelayCmdBetweenTwoIrCmd.get(9)).getDelayMillisecond() == 800); Assert.assertTrue(containMultiDelayCmdBetweenTwoIrCmd.get(10) instanceof IRCommand); }