RegistrationsRepository { public void saveRegistration(Registration registration) throws RegistrationPersistenceException { try { ObjectWriter writer = mapper.writer(); RegisterContext registerContext = registration.getRegisterContext(); String registerContextString = writer.writeValueAsString(registerContext); String expirationDate = registration.getExpirationDate().toString(); jdbcTemplate.update("insert into t_registrations(id,expirationDate,registerContext) values(?,?,?)", registerContext.getRegistrationId(), expirationDate, registerContextString); } catch (Exception e) { throw new RegistrationPersistenceException(e); } }  void saveRegistration(Registration registration); void updateRegistration(Registration registration); Map<String, Registration> getAllRegistrations(); Registration getRegistration(String registrationId); void removeRegistration(String registrationId);  }
@Test public void saveRegistrationTest() throws URISyntaxException, RegistrationPersistenceException { RegisterContext registerContext = createRegisterContextTemperature(); registerContext.setRegistrationId("12345"); Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext); registrationsRepository.saveRegistration(registration); Map<String, Registration> registrations = registrationsRepository.getAllRegistrations(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals(registration.getExpirationDate(), registrations.get("12345").getExpirationDate()); Assert.assertEquals(registerContext.getDuration(), registrations.get("12345").getRegisterContext().getDuration()); }
@Test public void saveRegistrationWithDuplicateKeyExceptionTest() throws URISyntaxException, RegistrationPersistenceException { thrown.expect(RegistrationPersistenceException.class); RegisterContext registerContext = createRegisterContextTemperature(); registerContext.setRegistrationId("12345"); Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext); registrationsRepository.saveRegistration(registration); registrationsRepository.saveRegistration(registration); }