SimpleRegisterServer implements RegistriesServer { void validateParticipants(Participant[] participants) throws InternalLogicException { Map<String, Participant> participantsById = new HashMap<>(); if (participants == null || participants.length == 0) throw new InternalLogicException("validateAndMapParticipants failed. participants are null or empty."); for (int i = 0; i < participants.length; i++) { Participant p = participants[i]; if (p == null || p.getId() == null || p.getId().isEmpty() || p.getName() == null || p.getName().isEmpty() || p.getPublicKey() == null || p.getPublicKey().isEmpty()) throw new InternalLogicException(String.format("validateAndMapParticipants failed. One of the participant fields are incorrect. index=%d", i)); if (participantsById.containsKey(p.getId())) throw new InternalLogicException(String.format("validateAndMapParticipants failed. Participant with id %s is represented twice.", p.getId())); participantsById.put(p.getId(), p); } } SimpleRegisterServer(Participant[] participants); Participant[] getParticipants();  }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsNull() throws Exception { manager.validateParticipants(null); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsEmpty() throws Exception { manager.validateParticipants(new Participant[0]); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsNullId() throws Exception { final Participant[] participants = new Participant[1]; participants[0] = new Participant(null, "name", "public_key"); manager.validateParticipants(participants); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsEmptyId() throws Exception { final Participant[] participants = new Participant[1]; participants[0] = new Participant("", "name", "public_key"); manager.validateParticipants(participants); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsNullName() throws Exception { final Participant[] participants = new Participant[1]; participants[0] = new Participant("id", null, "public_key"); manager.validateParticipants(participants); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsNullKey() throws Exception { final Participant[] participants = new Participant[1]; participants[0] = new Participant("id", "name", null); manager.validateParticipants(participants); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsEmptyKey() throws Exception { final Participant[] participants = new Participant[1]; participants[0] = new Participant("id", "name", ""); manager.validateParticipants(participants); }
@Test(expected=InternalLogicException.class) public void testValidateAndMapParticipantsSameId() throws Exception { final Participant[] participants = new Participant[2]; participants[0] = new Participant("id", "name1", "key1"); participants[1] = new Participant("id", "name2", "key2"); manager.validateParticipants(participants); }