DomainRoleMembersFetcherCommon { public Set<String> getDomainRoleMembers(String roleName, List<Role> roles) { if (roles == null) { return new HashSet<>(); } for (Role role : roles) { if (role.getName() == null) { continue; } if (role.getName().equals(roleName)) { if (role.getRoleMembers() == null) { return new HashSet<>(); } return role.getRoleMembers().stream() .filter(this::isUnexpiredUser) .map(RoleMember::getMemberName).collect(Collectors.toSet()); } } return new HashSet<>(); } DomainRoleMembersFetcherCommon(String userDomainPrefix); Set<String> getDomainRoleMembers(String roleName, List<Role> roles);  }
@Test public void testGetDomainRoleMembers() { DomainRoleMembersFetcherCommon fetcherCommon = new DomainRoleMembersFetcherCommon(USER_DOMAIN_PREFIX); long currentTimeInMillis = System.currentTimeMillis(); Timestamp futureTimeStamp = Timestamp.fromMillis(currentTimeInMillis + 100000); Timestamp pastTimeStamp = Timestamp.fromMillis(currentTimeInMillis - 100000); Role role1 = new Role(); role1.setName("role1"); RoleMember roleMember1 = new RoleMember().setMemberName("user.unexpiredUser").setExpiration(futureTimeStamp); RoleMember roleMember2 = new RoleMember().setMemberName("user.expiredUser").setExpiration(pastTimeStamp); RoleMember roleMember3 = new RoleMember().setMemberName("user.noExpiration"); RoleMember roleMember4 = new RoleMember().setMemberName("notProperUsername"); List<RoleMember> role1MemberList = new ArrayList<>(Arrays.asList(roleMember1, roleMember2, roleMember3, roleMember4)); role1.setRoleMembers(role1MemberList); Role role2 = new Role(); role2.setName("role2"); Role role3 = new Role(); List<Role> rolesList = new ArrayList<>(); rolesList.add(role1); rolesList.add(role2); rolesList.add(role3); Set<String> receivedMembers = fetcherCommon.getDomainRoleMembers("role1", rolesList); assertEquals(2, receivedMembers.size()); assertTrue(receivedMembers.contains("user.unexpiredUser")); assertTrue(receivedMembers.contains("user.noExpiration")); receivedMembers = fetcherCommon.getDomainRoleMembers("role2", rolesList); assertEquals(new HashSet<>(), receivedMembers); receivedMembers = fetcherCommon.getDomainRoleMembers("roleDoesntExist", rolesList); assertEquals(new HashSet<>(), receivedMembers); }