StudentMappingByMartikelNumber extends AbstractMappingByInstitutionalIdentifier { public Identity tryToMap(Student student) { Identity identity = tryToMap(UserConstants.INSTITUTIONAL_MATRICULATION_NUMBER, student.getRegistrationNr()); if (identity == null) { identity = tryToMap(UserConstants.INSTITUTIONAL_MATRICULATION_NUMBER, StringUtils.remove(student.getRegistrationNr(), "-")); } return identity; }  Identity tryToMap(Student student);  }
@Test public void tryToMap_foundNoMapping() { List<Identity> emptyResults = new ArrayList<Identity>(); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(emptyResults); Identity mappedIdentity = studentMappingByMartikelNumberTestObject.tryToMap(studentMock); assertNull("Must return null, when no mapping exists", mappedIdentity); }
@Test public void tryToMap_foundMoreThanOneMapping() { List<Identity> twoIdentities = new ArrayList<Identity>(); twoIdentities.add(identityMockOne); twoIdentities.add(identityMockTwo); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(twoIdentities); Identity mappedIdentity = studentMappingByMartikelNumberTestObject.tryToMap(studentMock); assertNull("Must return null, when more than one mapping exists", mappedIdentity); }
@Test public void tryToMap_foundOneMapping() { List<Identity> twoIdentities = new ArrayList<Identity>(); twoIdentities.add(identityMockOne); when( baseSecurityMock.getVisibleIdentitiesByPowerSearch(anyString(), anyMap(), anyBoolean(), any(SecurityGroup[].class), any(PermissionOnResourceable[].class), any(String[].class), any(Date.class), any(Date.class))).thenReturn(twoIdentities); Identity mappedIdentity = studentMappingByMartikelNumberTestObject.tryToMap(studentMock); assertNotNull("Must return an identity, when only one mapping exists", mappedIdentity); }