/**
  * Initialize
  *
  * @param command Command description
  * @param jython Jython interpreter, may be <code>null</code>
  */
 public LoopCommandImpl(final LoopCommand command, final JythonSupport jython) throws Exception {
   super(command, jython);
   reverse =
       (command.getStart() <= command.getEnd() && command.getStepSize() < 0)
           || (command.getStart() >= command.getEnd() && command.getStepSize() > 0);
   implementation = ScanCommandImplTool.getInstance().implement(command.getBody(), jython);
 }
  @Test
  public void testDeviceContextHelper() throws Exception {
    final MacroContext macros = new MacroContext("T=Test");

    final List<ScanCommand> commands =
        Arrays.asList(
            (ScanCommand) new SetCommand("device1", 3.14),
            (ScanCommand) new SetCommand("xpos", 2),
            (ScanCommand) new SetCommand("motor_x", 3));
    final JythonSupport jython = new JythonSupport();
    final List<ScanCommandImpl<?>> main_scan =
        ScanCommandImplTool.getInstance().implement(commands, jython);
    final DeviceContext device_context = new DeviceContext();
    DeviceContextHelper.addScanDevices(device_context, macros, main_scan);

    final Device[] devices = device_context.getDevices();
    System.out.println(Arrays.toString(devices));

    // Devices from commands, but account for motor_x = alias xpos
    assertThat(devices.length, equalTo(commands.size() - 1));

    // Check lookup via alias
    final Device aliased_device = device_context.getDevice("xpos");
    assertThat(aliased_device.getName(), equalTo("motor_x"));

    // Check lookup via 'real' name
    final Device real_device = device_context.getDevice("motor_x");
    assertThat(real_device, sameInstance(aliased_device));
  }