UserDevfileManager { public UserDevfile createDevfile(UserDevfile userDevfile) throws ServerException, NotFoundException, ConflictException { requireNonNull(userDevfile, "Required non-null userdevfile"); requireNonNull(userDevfile.getDevfile(), "Required non-null devfile"); String name = userDevfile.getName() != null ? userDevfile.getName() : NameGenerator.generate("devfile-", 5); UserDevfile result = userDevfileDao.create( new UserDevfileImpl( NameGenerator.generate("id-", 16), accountManager.getByName( EnvironmentContext.getCurrent().getSubject().getUserName()), name, userDevfile.getDescription(), userDevfile.getDevfile())); LOG.debug( "UserDevfile '{}' with id '{}' created by user '{}'", result.getName(), result.getId(), EnvironmentContext.getCurrent().getSubject().getUserName()); eventService.publish(new DevfileCreatedEvent(result)); return result; } @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 public void shouldGenerateUserDevfileIdOnCreation() throws Exception { final UserDevfileImpl userDevfile = new UserDevfileImpl(null, TEST_ACCOUNT, createUserDevfile()); when(userDevfileDao.create(any(UserDevfileImpl.class))) .thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]); UserDevfile actual = userDevfileManager.createDevfile(userDevfile); verify(userDevfileDao).create(userDevfileArgumentCaptor.capture()); assertFalse(isNullOrEmpty(userDevfileArgumentCaptor.getValue().getId())); assertEquals(new UserDevfileImpl(null, TEST_ACCOUNT, actual), userDevfile); }
@Test public void shouldSendDevfileCreatedEventOnCreation() throws Exception { final UserDevfileImpl userDevfile = new UserDevfileImpl(null, TEST_ACCOUNT, createUserDevfile()); when(userDevfileDao.create(any(UserDevfileImpl.class))) .thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]); UserDevfile expected = userDevfileManager.createDevfile(userDevfile); verify(eventService).publish(devfileCreatedEventCaptor.capture()); assertEquals(expected, devfileCreatedEventCaptor.getValue().getUserDevfile()); }