Пример #1
0
  @Test
  public void shouldBuildReviewInput() {
    Review review = ReviewBuilder.buildReview();

    ReviewInput reviewInput = new ReviewInputBuilder().toReviewInput(review);

    assertThat(reviewInput.message).isEqualTo("Total 8 violations found");
    assertThat(reviewInput.comments).hasSize(4);
    assertThat(reviewInput.comments.get("filename1")).hasSize(2);
    assertThat(reviewInput.comments.get("filename1").get(0).getMessage()).isEqualTo("test1");
    assertThat(reviewInput.labels.get("Code-Review")).isEqualTo(1);
  }
  @Test
  public void shouldNotLimitCommentsIfCountIsBelowMaximumCount() {
    Configuration config = new ConfigurationSetup().setUp(Collections.<String, String>emptyMap());
    Review review = ReviewBuilder.buildReview(config);

    new LimitCommentVisitor(10).afterReview(review);

    assertThat(review.getFiles()).hasSize(4);
    assertThat(review.getMessages()).containsExactly("Total 8 violations found");
    assertThat(review.getFiles().get(0).getComments()).hasSize(2);
    assertThat(review.getFiles().get(1).getComments()).hasSize(2);
    assertThat(review.getFiles().get(2).getComments()).hasSize(2);
    assertThat(review.getFiles().get(3).getComments()).hasSize(2);
  }
  @Test
  public void shouldLimitCommentsIfCountIsHigherMaximumCount() {
    Configuration config = new ConfigurationSetup().setUp(Collections.<String, String>emptyMap());
    Review review = ReviewBuilder.buildReview(config);

    new LimitCommentVisitor(3).afterReview(review);

    assertThat(review.getFiles()).hasSize(4);
    assertThat(review.getMessages())
        .containsExactly(
            "Total 8 violations found",
            "Showing only first 3 comments. 5 comments are filtered out");
    assertThat(review.getFiles().get(0).getComments()).hasSize(2);
    assertThat(review.getFiles().get(1).getComments()).hasSize(1);
    assertThat(review.getFiles().get(2).getComments()).isEmpty();
    assertThat(review.getFiles().get(3).getComments()).isEmpty();
  }