@Test void validate_WillFail_WhenOrganizationDoesNotExist() { when(organizationsReadService.getById(ORGANIZATION_ID_1)).thenThrow(NoSuchElementException.class); assertThrows(IllegalStateException.class, () -> organizationStatusValidator.validate((OrganizationStatusValidatableCommand) () -> ORGANIZATION_ID_1)); }
@Override public void validate(OrganizationStatusValidatableCommand command) { Organization organization; try { organization = organizationsReadService.getById(command.getOrganizationId()); } catch (NoSuchElementException e) { throw new IllegalStateException(String.format("Organization %s does not exist", command.getOrganizationId()), e); } Validate.validState(!organization.isDisabled(), "Organization %s is de-registered", command.getOrganizationId()); }
OrganizationStatusValidator implements Validates<OrganizationStatusValidatableCommand> { @Override public void validate(OrganizationStatusValidatableCommand command) { Organization organization; try { organization = organizationsReadService.getById(command.getOrganizationId()); } catch (NoSuchElementException e) { throw new IllegalStateException(String.format("Organization %s does not exist", command.getOrganizationId()), e); } Validate.validState(!organization.isDisabled(), "Organization %s is de-registered", command.getOrganizationId()); } }
OrganizationStatusValidator implements Validates<OrganizationStatusValidatableCommand> { @Override public void validate(OrganizationStatusValidatableCommand command) { Organization organization; try { organization = organizationsReadService.getById(command.getOrganizationId()); } catch (NoSuchElementException e) { throw new IllegalStateException(String.format("Organization %s does not exist", command.getOrganizationId()), e); } Validate.validState(!organization.isDisabled(), "Organization %s is de-registered", command.getOrganizationId()); } OrganizationStatusValidator(OrganizationsReadService organizationsReadService); }
OrganizationStatusValidator implements Validates<OrganizationStatusValidatableCommand> { @Override public void validate(OrganizationStatusValidatableCommand command) { Organization organization; try { organization = organizationsReadService.getById(command.getOrganizationId()); } catch (NoSuchElementException e) { throw new IllegalStateException(String.format("Organization %s does not exist", command.getOrganizationId()), e); } Validate.validState(!organization.isDisabled(), "Organization %s is de-registered", command.getOrganizationId()); } OrganizationStatusValidator(OrganizationsReadService organizationsReadService); @Override void validate(OrganizationStatusValidatableCommand command); }
OrganizationStatusValidator implements Validates<OrganizationStatusValidatableCommand> { @Override public void validate(OrganizationStatusValidatableCommand command) { Organization organization; try { organization = organizationsReadService.getById(command.getOrganizationId()); } catch (NoSuchElementException e) { throw new IllegalStateException(String.format("Organization %s does not exist", command.getOrganizationId()), e); } Validate.validState(!organization.isDisabled(), "Organization %s is de-registered", command.getOrganizationId()); } OrganizationStatusValidator(OrganizationsReadService organizationsReadService); @Override void validate(OrganizationStatusValidatableCommand command);  }