### Question:
EnvironmentStartService { public void startByCrn(String crn) { String accountId = ThreadBasedUserCrnProvider.getAccountId(); EnvironmentDto environment = environmentService.getByCrnAndAccountId(crn, accountId); start(environment, accountId); } EnvironmentStartService(EnvironmentReactorFlowManager reactorFlowManager,
            EnvironmentService environmentService); void startByCrn(String crn); void startByName(String name);  }### Answer:
@Test public void shouldStartEnvironmentWithoutParent() { EnvironmentDto environmentDto = getEnvironmentDto(); environmentDto.setParentEnvironmentCrn(null); when(environmentService.getByCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(environmentDto); ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.startByCrn(ENV_CRN)); verify(reactorFlowManager).triggerStartFlow(ENV_ID, ENV_NAME, USER_CRN); }
@Test public void shouldStartEnvironmentGivenParentIsAvailable() { EnvironmentDto environmentDto = getEnvironmentDto(); environmentDto.setParentEnvironmentCrn(PARENT_ENV_CRN); when(environmentService.getByCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(environmentDto); EnvironmentDto parentEnvironmentDto = new EnvironmentDto(); parentEnvironmentDto.setStatus(EnvironmentStatus.AVAILABLE); when(environmentService.getByCrnAndAccountId(PARENT_ENV_CRN, ACCOUNT_ID)).thenReturn(parentEnvironmentDto); ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.startByCrn(ENV_CRN)); verify(reactorFlowManager).triggerStartFlow(ENV_ID, ENV_NAME, USER_CRN); }
@Test public void shouldThrowBadRequestExceptionGivenParentIsNotAvailable() { EnvironmentDto environmentDto = getEnvironmentDto(); environmentDto.setParentEnvironmentCrn(PARENT_ENV_CRN); when(environmentService.getByCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(environmentDto); EnvironmentDto parentEnvironmentDto = new EnvironmentDto(); parentEnvironmentDto.setName("Parent-env-name"); parentEnvironmentDto.setStatus(EnvironmentStatus.ENV_STOPPED); when(environmentService.getByCrnAndAccountId(PARENT_ENV_CRN, ACCOUNT_ID)).thenReturn(parentEnvironmentDto); Assertions.assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.startByCrn(ENV_CRN))) .isInstanceOf(BadRequestException.class) .hasMessageContaining(parentEnvironmentDto.getName()); }