<commit_before>package de.cronn.jira.sync.service;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.net.MalformedURLException;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;

import de.cronn.jira.sync.config.JiraConnectionProperties;
import de.cronn.jira.sync.domain.JiraLoginRequest;
import de.cronn.jira.sync.domain.JiraLoginResponse;

@RunWith(MockitoJUnitRunner.class)
public class JiraServiceRestClientTest {

	@Mock
	private RestTemplateBuilder restTemplateBuilder;

	@Mock
	private RestTemplate restTemplate;

	@InjectMocks
	private JiraServiceRestClient jiraServiceRestClient;

	@Before
	public void prepareMocks() {
		doReturn(restTemplateBuilder).when(restTemplateBuilder).errorHandler(any());
		doReturn(restTemplate).when(restTemplateBuilder).build();
	}

	@Test
	public void testLoginWithValidParameters() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		jiraServiceRestClient.login(connectionProperties, true);

		verify(restTemplate).postForObject(eq("http://localhost/jira/rest/auth/1/session"), any(JiraLoginRequest.class), eq(JiraLoginResponse.class));
		verifyNoMoreInteractions(restTemplate);
	}

	@Test
	public void testLoginWithMissingUrl() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("url is missing");
	}

	@Test
	public void testLoginWithInvalidUrlProtocol() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl("unknown-scheme://foo-bar");

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("Illegal URL: 'unknown-scheme://foo-bar'")
			.withCauseExactlyInstanceOf(MalformedURLException.class)
			.withStackTraceContaining("unknown protocol: unknown-scheme");
	}

	@Test
	public void testLoginWithInvalidUrl() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl("http://foo:bar");

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("Illegal URL: 'http://foo:bar'")
			.withCauseExactlyInstanceOf(MalformedURLException.class)
			.withRootCauseExactlyInstanceOf(NumberFormatException.class)
			.withStackTraceContaining("For input string: \"bar\"");
	}

	@Test
	public void testLoginWithMissingUsername() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUsername(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("username is missing");
	}

	@Test
	public void testLoginWithMissingPassword() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setPassword(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("password is missing");
	}<commit_msg>fix JiraServiceRestClientTest on JDK9+<commit_after>package de.cronn.jira.sync.service;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.net.MalformedURLException;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;

import de.cronn.jira.sync.config.JiraConnectionProperties;
import de.cronn.jira.sync.domain.JiraLoginRequest;
import de.cronn.jira.sync.domain.JiraLoginResponse;

@RunWith(MockitoJUnitRunner.class)
public class JiraServiceRestClientTest {

	@Mock
	private RestTemplateBuilder restTemplateBuilder;

	@Mock
	private RestTemplate restTemplate;

	@InjectMocks
	private JiraServiceRestClient jiraServiceRestClient;

	@Before
	public void prepareMocks() {
		doReturn(restTemplateBuilder).when(restTemplateBuilder).errorHandler(any());
		doReturn(restTemplate).when(restTemplateBuilder).build();
	}

	@Test
	public void testLoginWithValidParameters() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		jiraServiceRestClient.login(connectionProperties, true);

		verify(restTemplate).postForObject(eq("http://localhost/jira/rest/auth/1/session"), any(JiraLoginRequest.class), eq(JiraLoginResponse.class));
		verifyNoMoreInteractions(restTemplate);
	}

	@Test
	public void testLoginWithMissingUrl() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("url is missing");
	}

	@Test
	public void testLoginWithInvalidUrlProtocol() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl("unknown-scheme://foo-bar");

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("Illegal URL: 'unknown-scheme://foo-bar'")
			.withCauseExactlyInstanceOf(MalformedURLException.class)
			.withStackTraceContaining("unknown protocol: unknown-scheme");
	}

	@Test
	public void testLoginWithInvalidUrl() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUrl("http://foo:bar");

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("Illegal URL: 'http://foo:bar'")
			.withCauseExactlyInstanceOf(MalformedURLException.class)
			.withRootCauseExactlyInstanceOf(NumberFormatException.class);
	}

	@Test
	public void testLoginWithMissingUsername() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setUsername(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("username is missing");
	}

	@Test
	public void testLoginWithMissingPassword() throws Exception {
		JiraConnectionProperties connectionProperties = validConnectionProperties();
		connectionProperties.setPassword(null);

		assertThatExceptionOfType(IllegalArgumentException.class)
			.isThrownBy(() -> jiraServiceRestClient.login(connectionProperties, true))
			.withMessage("password is missing");
	}
{'fraction_non_alphanumeric': 0.10014947683109118, 'fraction_numerical': 0.00040766408479412964, 'mean_word_length': 7.32579185520362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4671630', 'n_tokens_mistral': 2139, 'n_tokens_neox': 1986, 'n_words': 327}