### Question:
CommandRestController { @GetMapping("/components/{component}/commands") public Iterable<ComponentCommand> getByComponent(@PathVariable("component") String component, @RequestParam("context") String context, Principal principal){ auditLog.info("[{}] Request to list all Commands for which component \"{}\" in context \"{}\" has a registered handler.", AuditLog.username(principal), component, context); return new ComponentItems<>(component, context, new DefaultCommands( registrationCache)); } CommandRestController(CommandDispatcher commandDispatcher, CommandRegistrationCache registrationCache); @GetMapping("/components/{component}/commands") Iterable<ComponentCommand> getByComponent(@PathVariable("component") String component, @RequestParam("context") String context, Principal principal); @GetMapping("commands") List<JsonClientMapping> get(Principal principal); @PostMapping("commands/run") @ApiImplicitParams({ @ApiImplicitParam(name = TOKEN_PARAM, value = "Access Token", required = false, dataType = "string", paramType = "header") }) Future<CommandResponseJson> execute(@RequestHeader(value = CONTEXT_PARAM, defaultValue = Topology.DEFAULT_CONTEXT, required = false) String context,
                                               @RequestBody @Valid CommandRequestJson command, Principal principal); @GetMapping("commands/queues") List<JsonQueueInfo> queues(Principal principal); @GetMapping("commands/count") int count(Principal principal);  }### Answer:
@Test public void getByComponent(){ Iterator<ComponentCommand> iterator = testSubject.getByComponent("component", Topology.DEFAULT_CONTEXT, null).iterator(); assertTrue(iterator.hasNext()); GsonMedia gsonMedia = new GsonMedia(); iterator.next().printOn(gsonMedia); assertEquals("{\"name\":\"DoIt\"}", gsonMedia.toString()); assertFalse(iterator.hasNext()); }
@Test public void getByNotExistingComponent(){ Iterator<ComponentCommand> iterator = testSubject.getByComponent("otherComponent", Topology.DEFAULT_CONTEXT, null).iterator(); assertFalse(iterator.hasNext()); }