aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api/src/test
diff options
context:
space:
mode:
authorAntoine Vinot <antoine.vinot@sonarsource.com>2022-08-19 17:05:25 +0200
committersonartech <sonartech@sonarsource.com>2022-08-30 20:03:14 +0000
commitf6f59ecbf8e15e3b251bb0a44a0846b5acca7ea4 (patch)
treef3514b1b4e3134efef821fb3563fb5e05178a91d /server/sonar-webserver-api/src/test
parentad1024286aff2d16a3b3aa5f926613d596348f91 (diff)
downloadsonarqube-f6f59ecbf8e15e3b251bb0a44a0846b5acca7ea4.tar.gz
sonarqube-f6f59ecbf8e15e3b251bb0a44a0846b5acca7ea4.zip
SONAR-17210 - Update Github Scanning Alerts on status changes
Diffstat (limited to 'server/sonar-webserver-api/src/test')
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java50
1 files changed, 36 insertions, 14 deletions
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java
index cd83615d99b..e5215ae5f31 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java
@@ -64,20 +64,20 @@ public class QGChangeEventListenersImplTest {
@Rule
public LogTester logTester = new LogTester();
- private QGChangeEventListener listener1 = mock(QGChangeEventListener.class);
- private QGChangeEventListener listener2 = mock(QGChangeEventListener.class);
- private QGChangeEventListener listener3 = mock(QGChangeEventListener.class);
- private List<QGChangeEventListener> listeners = Arrays.asList(listener1, listener2, listener3);
+ private final QGChangeEventListener listener1 = mock(QGChangeEventListener.class);
+ private final QGChangeEventListener listener2 = mock(QGChangeEventListener.class);
+ private final QGChangeEventListener listener3 = mock(QGChangeEventListener.class);
+ private final List<QGChangeEventListener> listeners = Arrays.asList(listener1, listener2, listener3);
- private String project1Uuid = RandomStringUtils.randomAlphabetic(6);
- private BranchDto project1 = newBranchDto(project1Uuid);
- private DefaultIssue component1Issue = newDefaultIssue(project1Uuid);
- private List<DefaultIssue> oneIssueOnComponent1 = singletonList(component1Issue);
- private QGChangeEvent component1QGChangeEvent = newQGChangeEvent(project1);
+ private final String project1Uuid = RandomStringUtils.randomAlphabetic(6);
+ private final BranchDto project1 = newBranchDto(project1Uuid);
+ private final DefaultIssue component1Issue = newDefaultIssue(project1Uuid);
+ private final List<DefaultIssue> oneIssueOnComponent1 = singletonList(component1Issue);
+ private final QGChangeEvent component1QGChangeEvent = newQGChangeEvent(project1);
- private InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
+ private final InOrder inOrder = Mockito.inOrder(listener1, listener2, listener3);
- private QGChangeEventListenersImpl underTest = new QGChangeEventListenersImpl(new QGChangeEventListener[] {listener1, listener2, listener3});
+ private final QGChangeEventListenersImpl underTest = new QGChangeEventListenersImpl(new QGChangeEventListener[] {listener1, listener2, listener3});
@Test
public void broadcastOnIssueChange_has_no_effect_when_issues_are_empty() {
@@ -149,9 +149,9 @@ public class QGChangeEventListenersImplTest {
List<String> traceLogs = logTester.logs(LoggerLevel.TRACE);
assertThat(traceLogs).hasSize(3)
.containsOnly(
- "calling onChange() on listener " + listener1.getClass().getName() + " for events " + component1QGChangeEvent.toString() + "...",
- "calling onChange() on listener " + listener2.getClass().getName() + " for events " + component1QGChangeEvent.toString() + "...",
- "calling onChange() on listener " + listener3.getClass().getName() + " for events " + component1QGChangeEvent.toString() + "...");
+ "calling onChange() on listener " + listener1.getClass().getName() + " for events " + component1QGChangeEvent + "...",
+ "calling onChange() on listener " + listener2.getClass().getName() + " for events " + component1QGChangeEvent + "...",
+ "calling onChange() on listener " + listener3.getClass().getName() + " for events " + component1QGChangeEvent + "...");
}
@Test
@@ -253,6 +253,28 @@ public class QGChangeEventListenersImplTest {
}
@Test
+ public void isVulnerability_returns_true_if_issue_is_of_type_vulnerability() {
+ DefaultIssue defaultIssue = new DefaultIssue();
+ defaultIssue.setStatus(Issue.STATUS_OPEN);
+ defaultIssue.setType(RuleType.VULNERABILITY);
+
+ ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+ assertThat(changedIssue.isVulnerability()).isTrue();
+ }
+
+ @Test
+ public void isVulnerability_returns_false_if_issue_is_not_of_type_vulnerability() {
+ DefaultIssue defaultIssue = new DefaultIssue();
+ defaultIssue.setStatus(Issue.STATUS_OPEN);
+ defaultIssue.setType(RuleType.BUG);
+
+ ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+ assertThat(changedIssue.isVulnerability()).isFalse();
+ }
+
+ @Test
public void test_status_mapping() {
assertThat(ChangedIssueImpl.statusOf(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isEqualTo(QGChangeEventListener.Status.OPEN);
assertThat(ChangedIssueImpl.statusOf(new DefaultIssue().setStatus(Issue.STATUS_REOPENED))).isEqualTo(QGChangeEventListener.Status.REOPENED);