CampuskursCoOwners { public List<Identity> getDefaultCoOwners() { if (identites != null) { return identites; } else { identites = initCoOwnerIdentities(); return identites; } }  List<Identity> getDefaultCoOwners();  }
@Test public void getDefaultCoOwners_emptyCoOwnerNames() { String EMPTY_CO_OWNER_NAMES = ""; when(campusConfigurationMock.getDefaultCoOwnerUserNames()).thenReturn(EMPTY_CO_OWNER_NAMES); List<Identity> coOwners = campuskursCoOwnersTestObject.getDefaultCoOwners(); assertEquals("Wrong number of owners, must 0 when value is empty", 0, coOwners.size()); }
@Test public void getDefaultCoOwners_notExistingCoOwnerName() { String nonExistingCoOwnerNames = "test1,test2"; when(campusConfigurationMock.getDefaultCoOwnerUserNames()).thenReturn(nonExistingCoOwnerNames); List<Identity> coOwners = campuskursCoOwnersTestObject.getDefaultCoOwners(); assertEquals("Wrong number of owners, must be 0 when no identities exist", 0, coOwners.size()); }
@Test public void getDefaultCoOwners_oneCoOwnerName() { String coOwnerName = "test1"; Identity coOwnerIdentityMock = mock(Identity.class); when(campusConfigurationMock.getDefaultCoOwnerUserNames()).thenReturn(coOwnerName); when(baseSecurityMock.findIdentityByName(coOwnerName)).thenReturn(coOwnerIdentityMock); List<Identity> coOwners = campuskursCoOwnersTestObject.getDefaultCoOwners(); assertEquals("Wrong number of owners", 1, coOwners.size()); }
@Test public void getDefaultCoOwners_twoCoOwnerName() { String coOwnerName = "test1"; Identity coOwnerIdentityMock = mock(Identity.class); String secondCoOwnerName = "test2"; Identity secondCoOwnerIdentityMock = mock(Identity.class); String coOwnerConigValue = coOwnerName + "," + secondCoOwnerName; when(campusConfigurationMock.getDefaultCoOwnerUserNames()).thenReturn(coOwnerConigValue); when(baseSecurityMock.findIdentityByName(coOwnerName)).thenReturn(coOwnerIdentityMock); when(baseSecurityMock.findIdentityByName(secondCoOwnerName)).thenReturn(secondCoOwnerIdentityMock); List<Identity> coOwners = campuskursCoOwnersTestObject.getDefaultCoOwners(); assertEquals("Wrong number of owners", 2, coOwners.size()); }
@Test public void getDefaultCoOwners_duplicateCoOwnerName() { String coOwnerName = "test3"; Identity coOwnerIdentityMock = mock(Identity.class); String coOwnerConigValue = coOwnerName + "," + coOwnerName; when(campusConfigurationMock.getDefaultCoOwnerUserNames()).thenReturn(coOwnerConigValue); when(baseSecurityMock.findIdentityByName(coOwnerName)).thenReturn(coOwnerIdentityMock); List<Identity> coOwners = campuskursCoOwnersTestObject.getDefaultCoOwners(); assertEquals("Wrong number of owners, duplicate identity can be added only once", 1, coOwners.size()); }