### Question:
ComponentConfigProviderService { public void replaceImageComponentWithNew(Component component) { Component componentEntity = componentRepository.findComponentByStackIdComponentTypeName(component.getStack().getId(), component.getComponentType(), component.getName()).orElseThrow(NotFoundException.notFound("component", component.getName())); componentEntity.setAttributes(component.getAttributes()); componentEntity.setName(component.getName()); componentRepository.save(componentEntity); }  @Nullable Component getComponent(Long stackId, ComponentType componentType, String name); Set<Component> getAllComponentsByStackIdAndType(Long stackId, Set<ComponentType> componentTypes); Set<Component> getComponentsByStackId(Long stackId); Image getImage(Long stackId); Telemetry getTelemetry(Long stackId); CloudbreakDetails getCloudbreakDetails(Long stackId); StackTemplate getStackTemplate(Long stackId); Component store(Component component); Iterable<Component> store(Iterable<Component> components); void deleteComponentsForStack(Long stackId); void replaceImageComponentWithNew(Component component);  }### Answer:
@Test public void replaceImageComponentWithNew() { Stack stack = new Stack(); stack.setId(1L); Component original = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json("asdf"), stack); Component modified = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json("fdas"), stack); when(componentRepository.findComponentByStackIdComponentTypeName(eq(stack.getId()), eq(original.getComponentType()), eq(original.getName()))) .thenReturn(Optional.of(original)); componentConfigProviderService.replaceImageComponentWithNew(modified); ArgumentCaptor<Component> argument = ArgumentCaptor.forClass(Component.class); verify(componentRepository).save(argument.capture()); assertEquals(modified.getAttributes(), argument.getValue().getAttributes()); }