@Test public void ignoreDuplicateVote() throws Exception { Account account = accountCitizen("foo"); String token = prepareAccessToken(account); VoteResource.VoteArticle voteArticle = new VoteResource.VoteArticle(); voteArticle.articleId = FlakeId.fromString("a"); voteArticle.newState = VoteState.DOWN; voteArticle.previousCount = 100L; voteArticle.previousState = VoteState.EMPTY; Mockito.doThrow(new DuplicateKeyException("vote dup")) .when(voteService) .voteArticle(eq(VoteState.DOWN), eq(FlakeId.fromString("a")), isA(Authorization.class), eq(VoteState.EMPTY), eq(100L)); mockMvc.perform(post("/api/vote/article").header(AccountAccessToken.HEADER_KEY, token) .contentType(MediaType.APPLICATION_JSON) .content(new ObjectMapper().writeValueAsBytes(voteArticle))).andExpect(status().isOk()); }
private void ignoreDuplicateVote(Runnable runnable) { try { runnable.run(); } catch (DuplicateKeyException ignore) { } }
VoteResource { private void ignoreDuplicateVote(Runnable runnable) { try { runnable.run(); } catch (DuplicateKeyException ignore) { } } }
VoteResource { private void ignoreDuplicateVote(Runnable runnable) { try { runnable.run(); } catch (DuplicateKeyException ignore) { } }  }
VoteResource { private void ignoreDuplicateVote(Runnable runnable) { try { runnable.run(); } catch (DuplicateKeyException ignore) { } }  @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void voteArticle(AccountAccessToken token, @Valid @RequestBody VoteArticle request); @RequestMapping(value = "/debate", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void voteDebate(AccountAccessToken token, @Valid @RequestBody VoteDebate request); @RequestMapping(value = "/article-voters", method = RequestMethod.GET) List<ArticleVoterDto> listArticleVoters(AccountAccessToken token,
      @RequestParam("articleIds") List<String> articleIds); @RequestMapping(value = "/debate-voters", method = RequestMethod.GET) List<DebateVoterDto> lisDebateVoters(AccountAccessToken token,
      @RequestParam("articleId") FlakeId articleId); @RequestMapping(value = "/debate-voters-by-ids", method = RequestMethod.GET) List<DebateVoterDto> lisDebateVoters(AccountAccessToken token,
      @RequestParam("debateIds") List<String> debateIds); }
VoteResource { private void ignoreDuplicateVote(Runnable runnable) { try { runnable.run(); } catch (DuplicateKeyException ignore) { } }  @RequestMapping(value = "/article", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void voteArticle(AccountAccessToken token, @Valid @RequestBody VoteArticle request); @RequestMapping(value = "/debate", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }) void voteDebate(AccountAccessToken token, @Valid @RequestBody VoteDebate request); @RequestMapping(value = "/article-voters", method = RequestMethod.GET) List<ArticleVoterDto> listArticleVoters(AccountAccessToken token,
      @RequestParam("articleIds") List<String> articleIds); @RequestMapping(value = "/debate-voters", method = RequestMethod.GET) List<DebateVoterDto> lisDebateVoters(AccountAccessToken token,
      @RequestParam("articleId") FlakeId articleId); @RequestMapping(value = "/debate-voters-by-ids", method = RequestMethod.GET) List<DebateVoterDto> lisDebateVoters(AccountAccessToken token,
      @RequestParam("debateIds") List<String> debateIds);  }