AdminPermissionInitializer implements EventSubscriber<PostUserPersistedEvent> { @PostConstruct public void init() throws ServerException { try { User adminUser = userManager.getByName(name); grantSystemPermissions(adminUser.getId()); } catch (NotFoundException ex) { LOG.warn("Admin {} not found yet.", name); } finally { eventService.subscribe(this); } } @Inject  AdminPermissionInitializer(
      @Named("che.system.admin_name") String name,
      UserManager userManager,
      PermissionsManager permissionsManager,
      EventService eventService); @PostConstruct void init(); @PreDestroy void unsubscribe(); @Override void onEvent(PostUserPersistedEvent event); void grantSystemPermissions(String userId);  }
@Test public void shouldAddSystemPermissionsForExistedAdmin() throws Exception { when(userManager.getByName(eq(NAME))).thenReturn(adminUser); initializer.init(); verify(permissionsManager) .storePermission( argThat( (ArgumentMatcher<SystemPermissionsImpl>) argument -> ((SystemPermissionsImpl) argument).getUserId().equals(adminUser.getId()))); }
@Test public void shouldNotAddSystemPermissionsIfAdminNotExists() throws Exception { when(userManager.getByName(anyString())).thenThrow(NotFoundException.class); initializer.init(); verifyNoMoreInteractions(permissionsManager); }