@Test
  public void vote() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    Restaurant restaurantB =
        mapper.readValue(new StringReader(testRestaurantJson1), Restaurant.class);
    restaurantRepository.saveAndFlush(restaurantB);
    Restaurant restaurantA =
        mapper.readValue(new StringReader(testRestaurantJson2), Restaurant.class);
    restaurantRepository.saveAndFlush(restaurantA);

    doVote(restaurantB.getRestaurantName(), "qqq");
    doVote(restaurantB.getRestaurantName(), "www");
    doVote(restaurantB.getRestaurantName(), "ddd");

    doVote(restaurantA.getRestaurantName(), "kkk");
    doVote(restaurantA.getRestaurantName(), "lll");

    List<Vote> votes = votesRepository.findAll();
    // check all votes are here
    assertEquals(MAX_TOTAL_VOTES, votes.size());
    Map<Long, Long> res =
        votes.stream().collect(Collectors.groupingBy(Vote::getRestaurantId, Collectors.counting()));
    // check all votes counter correctly
    assertEquals(3l, res.get(restaurantB.getId()).longValue());
    assertEquals(2l, res.get(restaurantA.getId()).longValue());
  }
 private void checkResults(Restaurant restA, Restaurant restB) {
   List<Vote> votes = votesRepository.findAll();
   // check changing vote doesn't create new entries
   assertEquals(MAX_TOTAL_VOTES, votes.size());
   Map<Long, Long> res =
       votes.stream().collect(Collectors.groupingBy(Vote::getRestaurantId, Collectors.counting()));
   // check that vote actually changed
   assertEquals(2l, res.get(restB.getId()).longValue());
   assertEquals(3l, res.get(restA.getId()).longValue());
 }