UserDevfileManager { public UserDevfile updateUserDevfile(UserDevfile update) throws ConflictException, NotFoundException, ServerException { requireNonNull(update); Optional<UserDevfile> result = userDevfileDao.update(update); UserDevfile devfile = result.orElseThrow( () -> new NotFoundException( format("Devfile with id '%s' doesn't exist", update.getId()))); LOG.debug( "UserDevfile '{}' with id '{}' update by user '{}'", devfile.getName(), devfile.getId(), EnvironmentContext.getCurrent().getSubject().getUserName()); eventService.publish(new DevfileUpdatedEvent(devfile)); return devfile; } @Inject  UserDevfileManager(
      AccountManager accountManager, UserDevfileDao userDevfileDao, EventService eventService); UserDevfile createDevfile(UserDevfile userDevfile); UserDevfile getById(String id); Page<UserDevfile> getByNamespace(String namespace, int maxItems, long skipCount); UserDevfile updateUserDevfile(UserDevfile update); void removeUserDevfile(String id); Page<UserDevfile> getUserDevfiles(
      int maxItems,
      int skipCount,
      List<Pair<String, String>> filter,
      List<Pair<String, String>> order);  }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowNpeWhenUpdatingUserDevfileByNullId() throws Exception { userDevfileManager.updateUserDevfile(null); }
@Test public void shouldUpdateUserDevfile() throws Exception { final UserDevfileImpl userDevfile = createUserDevfile(); when(userDevfileDao.update(any(UserDevfileImpl.class))) .thenAnswer(invocationOnMock -> Optional.of(invocationOnMock.getArguments()[0])); userDevfileManager.updateUserDevfile(userDevfile); verify(userDevfileDao).update(eq(userDevfile)); }
@Test(expectedExceptions = NotFoundException.class) public void shouldThrowNotFoundIfUserDevfileIsNotFoundOnUpdate() throws Exception { final UserDevfileImpl userDevfile = createUserDevfile(); Mockito.doReturn(Optional.empty()).when(userDevfileDao).update(any(UserDevfileImpl.class)); userDevfileManager.updateUserDevfile(userDevfile); }
@Test public void shouldSendDevfileUpdatedEventOnUpdateDevfile() throws Exception { final UserDevfileImpl userDevfile = createUserDevfile(); when(userDevfileDao.update(any(UserDevfileImpl.class))) .thenAnswer(invocationOnMock -> Optional.of(invocationOnMock.getArguments()[0])); userDevfileManager.updateUserDevfile(userDevfile); verify(eventService).publish(devfileUpdatedEventCaptor.capture()); assertEquals(userDevfile, devfileUpdatedEventCaptor.getValue().getUserDevfile()); }