### Question:
EventRegistrationService { @Transactional public Registration register(Person person, Event event) { String error = ""; if (person == null) { error = error + "Person needs to be selected for registration! "; } else if (!personRepository.existsById(person.getName())) { error = error + "Person does not exist! "; } if (event == null) { error = error + "Event needs to be selected for registration!"; } else if (!eventRepository.existsById(event.getName())) { error = error + "Event does not exist!"; } if (registrationRepository.existsByPersonAndEvent(person, event)) { error = error + "Person is already registered to this event!"; } error = error.trim(); if (error.length() > 0) { throw new IllegalArgumentException(error); } Registration registration = new Registration(); registration.setId(person.getName().hashCode() * event.getName().hashCode()); registration.setPerson(person); registration.setEvent(event); registrationRepository.save(registration); return registration; }  @Transactional Person createPerson(String name); @Transactional Person getPerson(String name); @Transactional List<Person> getAllPersons(); @Transactional Event buildEvent(Event event, String name, Date date, Time startTime, Time endTime); @Transactional Event createEvent(String name, Date date, Time startTime, Time endTime); @Transactional Event getEvent(String name); @Transactional List<Event> getAllEvents(); @Transactional Registration register(Person person, Event event); @Transactional List<Registration> getAllRegistrations(); @Transactional Registration getRegistrationByPersonAndEvent(Person person, Event event); @Transactional List<Registration> getRegistrationsForPerson(Person person); @Transactional List<Registration> getRegistrationsByPerson(Person person); @Transactional List<Event> getEventsAttendedByPerson(Person person);  }### Answer:
@Test public void testRegister() { assertEquals(0, service.getAllRegistrations().size()); String nameP = "Oscar"; Person person = service.createPerson(nameP); assertEquals(1, service.getAllPersons().size()); String nameE = "Soccer Game"; Calendar c = Calendar.getInstance(); c.set(2017, Calendar.MARCH, 16, 9, 0, 0); Date eventDate = new Date(c.getTimeInMillis()); Time startTime = new Time(c.getTimeInMillis()); c.set(2017, Calendar.MARCH, 16, 10, 30, 0); Time endTime = new Time(c.getTimeInMillis()); Event event = service.createEvent(nameE, eventDate, startTime, endTime); assertEquals(1, service.getAllEvents().size()); try { service.register(person, event); } catch (IllegalArgumentException e) { fail(); } checkResultRegister(nameP, nameE, eventDate, startTime, endTime); }