選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CompatibilityTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * SonarQube Runner - Batch
  3. * Copyright (C) 2011 SonarSource
  4. * sonarqube@googlegroups.com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.runner.batch;
  21. import static org.mockito.Mockito.times;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.mockito.ArgumentCaptor;
  25. import static org.assertj.core.api.Assertions.assertThat;
  26. import static org.mockito.Mockito.mock;
  27. import static org.mockito.Mockito.verify;
  28. public class CompatibilityTest {
  29. private IssueListener issueListener;
  30. @Before
  31. public void setUp() {
  32. issueListener = mock(IssueListener.class);
  33. }
  34. @Test
  35. public void test() {
  36. org.sonar.batch.bootstrapper.IssueListener.Issue batchIssue = new org.sonar.batch.bootstrapper.IssueListener.Issue();
  37. setIssue(batchIssue);
  38. org.sonar.batch.bootstrapper.IssueListener adaptedIssueListener = Compatibility.getBatchIssueListener(issueListener, false);
  39. adaptedIssueListener.handle(batchIssue);
  40. ArgumentCaptor<IssueListener.Issue> arg = ArgumentCaptor.forClass(IssueListener.Issue.class);
  41. verify(issueListener).handle(arg.capture());
  42. assertIssue(arg.getValue(), false);
  43. }
  44. @Test
  45. public void testPrecise() {
  46. org.sonar.batch.bootstrapper.IssueListener.Issue batchIssue = new org.sonar.batch.bootstrapper.IssueListener.Issue();
  47. setIssue(batchIssue);
  48. org.sonar.batch.bootstrapper.IssueListener adaptedIssueListener = Compatibility.getBatchIssueListener(issueListener, true);
  49. adaptedIssueListener.handle(batchIssue);
  50. ArgumentCaptor<IssueListener.Issue> arg = ArgumentCaptor.forClass(IssueListener.Issue.class);
  51. verify(issueListener).handle(arg.capture());
  52. assertIssue(arg.getValue(), true);
  53. }
  54. @Test
  55. public void preciseIssueLocationCompatibility() {
  56. org.sonar.batch.bootstrapper.IssueListener.Issue batchIssue = mock(org.sonar.batch.bootstrapper.IssueListener.Issue.class);
  57. org.sonar.batch.bootstrapper.IssueListener adaptedIssueListener = Compatibility.getBatchIssueListener(issueListener, false);
  58. adaptedIssueListener.handle(batchIssue);
  59. verify(batchIssue, times(0)).getEndLine();
  60. verify(batchIssue, times(0)).getStartLine();
  61. verify(batchIssue, times(0)).getStartLineOffset();
  62. verify(batchIssue, times(0)).getEndLineOffset();
  63. }
  64. private static void setIssue(org.sonar.batch.bootstrapper.IssueListener.Issue issue) {
  65. issue.setAssigneeName("name");
  66. issue.setRuleName("rule");
  67. issue.setRuleKey("key");
  68. issue.setMessage("msg");
  69. issue.setAssigneeLogin("login");
  70. issue.setLine(10);
  71. issue.setStartLine(5);
  72. issue.setEndLine(6);
  73. issue.setStartLineOffset(1);
  74. issue.setEndLineOffset(2);
  75. issue.setComponentKey("component");
  76. issue.setSeverity("severity");
  77. issue.setNew(true);
  78. issue.setStatus("status");
  79. }
  80. private static void assertIssue(IssueListener.Issue issue, boolean precise) {
  81. assertThat(issue.getAssigneeName()).isEqualTo("name");
  82. assertThat(issue.getRuleName()).isEqualTo("rule");
  83. assertThat(issue.getRuleKey()).isEqualTo("key");
  84. assertThat(issue.getMessage()).isEqualTo("msg");
  85. assertThat(issue.getAssigneeLogin()).isEqualTo("login");
  86. assertThat(issue.getComponentKey()).isEqualTo("component");
  87. assertThat(issue.getSeverity()).isEqualTo("severity");
  88. assertThat(issue.isNew()).isEqualTo(true);
  89. assertThat(issue.getStatus()).isEqualTo("status");
  90. if (precise) {
  91. assertThat(issue.getStartLine()).isEqualTo(5);
  92. assertThat(issue.getEndLine()).isEqualTo(6);
  93. assertThat(issue.getStartLineOffset()).isEqualTo(1);
  94. assertThat(issue.getEndLineOffset()).isEqualTo(2);
  95. } else {
  96. assertThat(issue.getStartLine()).isEqualTo(10);
  97. assertThat(issue.getEndLine()).isEqualTo(10);
  98. assertThat(issue.getStartLineOffset()).isEqualTo(null);
  99. assertThat(issue.getEndLineOffset()).isEqualTo(null);
  100. }
  101. }
  102. }