@Test public void shouldCollectIssuesByPriority() throws Exception { Filter filter = new Filter(null, 1l, null, null, null, null, null, null, false); JiraSoapService jiraSoapService = mock(JiraSoapService.class); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings); when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any())) .thenReturn(wrapper); RemoteIssue issue1 = new RemoteIssue(); issue1.setPriority("1"); issue1.setId("1"); RemoteIssue issue2 = new RemoteIssue(); issue2.setPriority("1"); issue2.setId("2"); RemoteIssue issue3 = new RemoteIssue(); issue3.setPriority("2"); issue3.setId("3"); when(jiraSoapService.getIssuesFromFilter("token", "1")) .thenReturn(new RemoteIssue[] {issue1, issue2, issue3}); Map<Long, Integer> foundIssues = sensor.collectIssuesByPriority(wrapper, "token", filter); assertThat(foundIssues.size()).isEqualTo(2); assertThat(foundIssues.get(1l)).isEqualTo(2); assertThat(foundIssues.get(2l)).isEqualTo(1); }
@Test public void shouldInitRemoteIssueWithComponent() throws Exception { // Given that settings.setProperty(JiraConstants.JIRA_ISSUE_COMPONENT_ID, "123"); RemoteIssue expectedIssue = new RemoteIssue(); expectedIssue.setProject("TEST"); expectedIssue.setType("3"); expectedIssue.setPriority("4"); expectedIssue.setSummary("Sonar Issue #ABCD - Avoid cycle between java packages"); expectedIssue.setDescription( "Issue detail:\n{quote}\nThe Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.\n" + "{quote}\n\n\nCheck it on Sonar: http://my.sonar.com/issue/show/ABCD"); expectedIssue.setComponents(new RemoteComponent[] {new RemoteComponent("123", null)}); // Verify RemoteIssue returnedIssue = jiraIssueCreator.initRemoteIssue(sonarIssue, settings, ""); assertThat(returnedIssue).isEqualTo(expectedIssue); }
@Test public void shouldInitRemoteIssueWithoutName() throws Exception { // Given that when(ruleFinder.findByKey(RuleKey.of("squid", "CycleBetweenPackages"))) .thenReturn(org.sonar.api.rules.Rule.create().setName(null)); RemoteIssue expectedIssue = new RemoteIssue(); expectedIssue.setProject("TEST"); expectedIssue.setType("3"); expectedIssue.setPriority("4"); expectedIssue.setSummary("Sonar Issue #ABCD"); expectedIssue.setDescription( "Issue detail:\n{quote}\nThe Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.\n" + "{quote}\n\n\nCheck it on Sonar: http://my.sonar.com/issue/show/ABCD"); // Verify RemoteIssue returnedIssue = jiraIssueCreator.initRemoteIssue(sonarIssue, settings, ""); assertThat(returnedIssue.getSummary()).isEqualTo(expectedIssue.getSummary()); assertThat(returnedIssue.getDescription()).isEqualTo(expectedIssue.getDescription()); assertThat(returnedIssue).isEqualTo(expectedIssue); }