### Question:
InitService { public InitState setAdminUser(User adminUser, String password) throws InvalidInitStateException { isInitStateElseThrow(InitStateName.CREATE_USER); LocalUser user = ((LocalUserService) userService).createLocalUser(adminUser, false); passwordService.setPassword(user, password); adminUserService.addAdmin(createAdminUser(user)); return nextInitState(); }  @EventListener(ApplicationReadyEvent.class) void onApplicationEvent(); InitState getInitState(); InitState saveInitState(InitState initState); boolean checkInitState(InitStateName initStateName); InitState setOAuthClientDetails(OAuthClientDetails oauthClientDetails); InitState setAdminUser(User adminUser, String password); InitState setAzureAdminUser(AdminUser adminUser);  }### Answer:
@Test public void setAdminUser_throwsExceptionWhenInWrongInitState() { initState.setInitState(InitStateName.INITIALIZED); initState.setId(1L); iterable = Collections.singletonList(initState); when(initStateRepository.findAll()).thenReturn(iterable); try { initService.setAdminUser(new LocalUser(), "TestAbc"); fail(); } catch (Exception e) { assertTrue(e instanceof InvalidInitStateException); } }
@Test public void setAdminUser_createsUser() { initState.setInitState(InitStateName.CREATE_USER); initState.setId(1L); iterable = Collections.singletonList(initState); LocalUser localUser = new LocalUser(); when(initStateRepository.findAll()).thenReturn(iterable); when(localUserService.createLocalUser(localUser, false)).thenReturn(new LocalUser()); try { initService.setAdminUser(localUser, "TestAbc"); verify(localUserService).createLocalUser(localUser, false); } catch (Exception e) { fail(e.getClass().getName()); } }