### Question:
OrgMatchingItemProcessor extends BaseItemProcessor implements ItemProcessor<OrgData, OrgData> { @Override public OrgData process(OrgData input) throws Exception { ServiceContext context = getServiceContext(); List<ValidationError> errors = Lists.newArrayList(); if (StringUtils.isBlank(input.getOrg().getOrgTypeCode())) { ValidationError error = new ValidationError("orgTypeCode", "Organization Type", "The organization type is required."); errors.add(error); } if (StringUtils.isBlank(input.getOrg().getParentOrgCode())) { ValidationError error = new ValidationError("parentOrgCode", "Parent Organization", "The parent organization is required."); errors.add(error); } if (!errors.isEmpty()) { ValidationServiceException e = new ValidationServiceException(new FaultInfo()); e.getFaultInfo().getAttributeErrors().addAll(errors); throw e; } Org match = organizationService.getMatch(context, input.getOrg()); if (match != null) { if (!match.getParentOrgLocalCode().equals(input.getOrg().getParentOrgLocalCode())) { String msg = messageSource.getMessage("validation.org.parent.not.same", new Object[] { input.getOrg().getParentOrgLocalCode(), match.getParentOrgLocalCode() }, Locale.getDefault()); errors.add(new ValidationError("parentOrgCode", "Parent Organization", msg)); ValidationServiceException e = new ValidationServiceException(new FaultInfo()); e.getFaultInfo().getAttributeErrors().addAll(errors); throw e; } input.setOrg(match); return binder.bind(input, input.getFieldSet()); } return input; }  @Override OrgData process(OrgData input); void setOrganizationService(OrganizationService organizationService); void setBinder(Binder<OrgData> binder); void setMessageSource(MessageSource messageSource);  }### Answer:
@Test public void testNoMatch() throws Exception { FieldSet fieldSet = new DefaultFieldSet(OrgLineTokenizer.COL_NAMES, OrgLineTokenizer.COL_NAMES); orgData.setFieldSet(fieldSet); Mockito.when( organizationService.getMatch(org.mockito.Matchers.any(ServiceContext.class), org.mockito.Matchers.any(Org.class))).thenReturn(null); Map<String, String> asMap = orgData.getOrg().getAsMap(); OrgData matchedData = processor.process(orgData); Assert.assertTrue(matchedData.getOrg().getAsMap().equals(asMap)); }
@Test(expected = ValidationServiceException.class) public void testParentCodesNotMatch() throws Exception { FieldSet fieldSet = Mockito.mock(FieldSet.class); Mockito.when(fieldSet.readString(org.mockito.Matchers.argThat(Matchers.is("name")))).thenReturn(null); orgData.setFieldSet(fieldSet); Org match = new Org(); String name = "this was not in the fieldset"; match.setName(name); match.setParentOrgLocalCode("localCode"); Mockito.when( organizationService.getMatch(org.mockito.Matchers.any(ServiceContext.class), org.mockito.Matchers.any(Org.class))).thenReturn(match); OrgData matchedData = processor.process(orgData); Assert.assertNull(matchedData.getOrg().getName()); }
@Test public void testMatch() throws Exception { FieldSet fieldSet = Mockito.mock(FieldSet.class); Mockito.when(fieldSet.readString(org.mockito.Matchers.argThat(Matchers.is("name")))).thenReturn(null); orgData.setFieldSet(fieldSet); Org match = new Org(); String name = "this was not in the fieldset"; match.setName(name); match.setParentOrgLocalCode("parentLocalCode"); Mockito.when( organizationService.getMatch(org.mockito.Matchers.any(ServiceContext.class), org.mockito.Matchers.any(Org.class))).thenReturn(match); OrgData matchedData = processor.process(orgData); Assert.assertNull(matchedData.getOrg().getName()); }