### Question:
BonusService { @Transactional public void calculateBonus(Bonus bonus) { if (bonusRepository.existsById(bonus.getId())) { log.info("Bonus id {} already exists - ignored", bonus.getId()); } else { bonusRepository.save(bonus); } } @Autowired  BonusService(BonusRepository bonusRepository); @Transactional void calculateBonus(Bonus bonus);  }### Answer:
@Test public void ensureIdempotencySecondCallIgnored() { long countBefore = bonusRepository.count(); Bonus bonus = new Bonus(42L, new Customer(23L, "Eberhard", "Wolff"), new Date(0L), 42.0); bonusService.calculateBonus(bonus); assertThat(bonusRepository.count(), is(countBefore + 1)); assertThat(bonusRepository.findById(42L).get().getUpdated().getTime(), equalTo(0L)); bonus = new Bonus(42, new Customer(23L, "Eberhard", "Wolff"), new Date(), 42.0d); bonusService.calculateBonus(bonus); assertThat(bonusRepository.count(), is(countBefore + 1)); assertThat(bonusRepository.findById(42L).get().getUpdated().getTime(), equalTo(0L)); }