RegistrationsRepository { public void updateRegistration(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("update t_registrations set expirationDate=? , registerContext=? where id=?", expirationDate, registerContextString, registerContext.getRegistrationId()); } 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 updateRegistrationTest() 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("PT10S", registrations.get("12345").getRegisterContext().getDuration()); registerContext.setDuration("PT1D"); registration.setExpirationDate(Instant.now().plus(1, ChronoUnit.DAYS)); registrationsRepository.updateRegistration(registration); registrations = registrationsRepository.getAllRegistrations(); Assert.assertEquals(1, registrations.size()); Assert.assertEquals("PT1D", registrations.get("12345").getRegisterContext().getDuration()); Assert.assertEquals(registration.getExpirationDate(), registrations.get("12345").getExpirationDate()); }
@Test public void updateRegistrationWithExceptionTest() throws URISyntaxException, RegistrationPersistenceException { thrown.expect(RegistrationPersistenceException.class); Registration registration = new Registration(); registration.setRegisterContext(new RegisterContext()); registrationsRepository.updateRegistration(registration); }