@Test public void shouldFailToCreateIssueIfCantConnect() throws Exception { // Given that JiraSoapSession soapSession = mock(JiraSoapSession.class); doThrow(RemoteException.class).when(soapSession).connect(anyString(), anyString()); // Verify thrown.expect(IllegalStateException.class); thrown.expectMessage("Impossible to connect to the JIRA server"); jiraIssueCreator.doCreateIssue(sonarIssue, soapSession, settings, ""); }
@Test public void shouldCreateIssue() throws Exception { // Given that RemoteIssue issue = new RemoteIssue(); JiraSoapService jiraSoapService = mock(JiraSoapService.class); when(jiraSoapService.createIssue(anyString(), any(RemoteIssue.class))).thenReturn(issue); JiraSoapSession soapSession = mock(JiraSoapSession.class); when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService); // Verify RemoteIssue returnedIssue = jiraIssueCreator.doCreateIssue(sonarIssue, soapSession, settings, ""); verify(soapSession).connect("foo", "bar"); verify(soapSession).getJiraSoapService(); verify(soapSession).getAuthenticationToken(); assertThat(returnedIssue).isEqualTo(issue); }