NewCaseInstancePresenter extends AbstractPresenter<NewCaseInstancePresenter.NewCaseInstanceView> { protected boolean validateCaseOwnerAssignment(String ownerInput) { final Integer ownerRoleCardinality = 1; boolean isAssignmentValid = true; final List<String> ownerInputList = Splitter.on(",") .trimResults() .omitEmptyStrings() .splitToList(ofNullable(ownerInput).orElse("")); final String ownerInputFiltered = Joiner.on(", ").join(ownerInputList); if (!ownerInputFiltered.equals(ownerInput)) { view.setOwner(ownerInputFiltered); } if (ownerInputFiltered.isEmpty()) { view.showCaseOwnerError(translationService.format(Constants.PLEASE_PROVIDE_CASE_OWNER)); isAssignmentValid = false; } else if (ownerInputList.size() > ownerRoleCardinality) { view.showCaseOwnerError(translationService.format(Constants.INVALID_ROLE_ASSIGNMENT, "owner", ownerRoleCardinality)); isAssignmentValid = false; } return isAssignmentValid; }  void show(); @Inject void setNotification(final Event<NotificationEvent> notification); @Inject void setNewCaseEvent(final Event<CaseCreatedEvent> newCaseEvent); @Inject void setCaseService(final Caller<CaseManagementService> caseService);  }
@Test public void testValidateCaseOwnerAssignment_validAssignment() { final String caseOwners = "caseOwner"; assertThat(presenter.validateCaseOwnerAssignment(caseOwners)) .as("isAssignmentValid") .isTrue(); verifyZeroInteractions(view); }
@Test public void testValidateCaseOwnerAssignment_validAssignmentAfterFiltering() { final String caseOwners = "caseOwner"; assertThat(presenter.validateCaseOwnerAssignment(" , ," + caseOwners + " ,,, ")) .as("isAssignmentValid") .isTrue(); verify(view).setOwner(caseOwners); verifyNoMoreInteractions(view); }
@Test public void testValidateCaseOwnerAssignment_emptyInput() { List<String> emptyInputs = new ArrayList<>(asList(null, " ", " , ")); emptyInputs.forEach(emptyInput -> assertThat(presenter.validateCaseOwnerAssignment(emptyInput)) .as("isAssignmentValid") .isFalse()); verify(view, times(3)).setOwner(anyString()); verify(view, times(3)).showCaseOwnerError(anyString()); verify(translationService, times(3)).format(eq("PleaseProvideCaseOwner")); }
@Test public void testValidateCaseOwnerAssignment_caseOwnerRoleCardinalityExceeded() { final String caseOwnerRole = "owner"; final Integer ownerRoleCardinality = 1; final String caseOwners = "testOwner1, testOwner2"; assertThat(presenter.validateCaseOwnerAssignment(caseOwners)) .as("isAssignmentValid") .isFalse(); verify(view, never()).setOwner(anyString()); verify(view).showCaseOwnerError(anyString()); verify(translationService).format(eq("InvalidRoleAssignment"), eq(caseOwnerRole), eq(ownerRoleCardinality)); }