<commit_before>package hudson.plugins.jira;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainSpecification;
import com.cloudbees.plugins.credentials.domains.HostnameSpecification;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

/**
 * @author <NAME>
 */
public class CredentialsHelperTest {
	@Rule
	public JenkinsRule r = new JenkinsRule();

	@Test
	public void testLookupSystemCredentials() throws IOException {
		assertNull(CredentialsHelper.lookupSystemCredentials("nonexistent-credentials-id", null));

		StandardUsernamePasswordCredentials c = new UsernamePasswordCredentialsImpl(
				CredentialsScope.SYSTEM,
				null,
				null,
				"username",
				"password"
		);
		CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);

		assertEquals(c, CredentialsHelper.lookupSystemCredentials(c.getId(), null));
		assertEquals(c, CredentialsHelper.lookupSystemCredentials(c.getId(), new URL("http://example.org")));
	}

	@Test
	public void testLookupSystemCredentialsWithDomainRestriction() throws IOException {
		Domain domain = new Domain("example", "test domain", Arrays.<DomainSpecification>asList(new HostnameSpecification("example.org", null)));
		StandardUsernamePasswordCredentials c = new UsernamePasswordCredentialsImpl(
				CredentialsScope.SYSTEM,
				null,
				null,
				"username",
				"password"
		);
		CredentialsProvider.lookupStores(r.jenkins).iterator().next().addDomain(domain, c);

		assertEquals(c, CredentialsHelper.lookupSystemCredentials(c.getId(), null));
		assertEquals(c, CredentialsHelper.lookupSystemCredentials(c.getId(), new URL("http://example.org")));
		assertNull(CredentialsHelper.lookupSystemCredentials(c.getId(), new URL("http://nonexistent.url")));
	}

	@Test
	public void testMigrateCredentials() throws MalformedURLException {
		assertThat(CredentialsProvider.lookupStores(r.jenkins).iterator().next().getCredentials(Domain.global()), empty());

		StandardUsernamePasswordCredentials c = CredentialsHelper.migrateCredentials("username", "password", new URL("http://example.org"));

		assertEquals("Migrated by JIRA Plugin", c.getDescription());
		assertThat(CredentialsProvider.lookupStores(r.jenkins).iterator().next().getCredentials(Domain.global()), hasSize(1));
	}

	@Test
	public void testMigrateCredentialsWithExsitingCredentials() throws IOException {
		Domain domain = new Domain("example", "test domain", Arrays.<DomainSpecification>asList(new HostnameSpecification("example.org", null)));
		StandardUsernamePasswordCredentials c = new UsernamePasswordCredentialsImpl(
				CredentialsScope.SYSTEM,
				null,
				null,
				"username",
				"password"
		);
		CredentialsProvider.lookupStores(r.jenkins).iterator().next().addDomain(domain, c);

		StandardUsernamePasswordCredentials cred = CredentialsHelper.migrateCredentials("username", "password", new URL("http://example.org"));

		assertEquals(c, cred);
	}
}<commit_msg>no functional changes, only get rid of tabs and formatting<commit_after>package hudson.plugins.jira;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.domains.DomainSpecification;
import com.cloudbees.plugins.credentials.domains.HostnameSpecification;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;

/**
 * @author <NAME>
 */
public class CredentialsHelperTest
{
    @Rule
    public JenkinsRule r = new JenkinsRule();

    @Test
    public void testLookupSystemCredentials()
        throws IOException
    {
        assertNull( CredentialsHelper.lookupSystemCredentials( "nonexistent-credentials-id", null ) );

        StandardUsernamePasswordCredentials c =
            new UsernamePasswordCredentialsImpl( CredentialsScope.SYSTEM, null, null, "username", "password" );
        CredentialsProvider.lookupStores( r.jenkins ).iterator().next().addCredentials( Domain.global(), c );

        assertEquals( c, CredentialsHelper.lookupSystemCredentials( c.getId(), null ) );
        assertEquals( c, CredentialsHelper.lookupSystemCredentials( c.getId(), new URL( "http://example.org" ) ) );
    }

    @Test
    public void testLookupSystemCredentialsWithDomainRestriction()
        throws IOException
    {
        Domain domain = new Domain( "example", "test domain", Arrays.<DomainSpecification>asList(
            new HostnameSpecification( "example.org", null ) ) );
        StandardUsernamePasswordCredentials c =
            new UsernamePasswordCredentialsImpl( CredentialsScope.SYSTEM, null, null, "username", "password" );
        CredentialsProvider.lookupStores( r.jenkins ).iterator().next().addDomain( domain, c );

        assertEquals( c, CredentialsHelper.lookupSystemCredentials( c.getId(), null ) );
        assertEquals( c, CredentialsHelper.lookupSystemCredentials( c.getId(), new URL( "http://example.org" ) ) );
        assertNull( CredentialsHelper.lookupSystemCredentials( c.getId(), new URL( "http://nonexistent.url" ) ) );
    }

    @Test
    public void testMigrateCredentials()
        throws MalformedURLException
    {
        assertThat( CredentialsProvider.lookupStores( r.jenkins ).iterator().next().getCredentials( Domain.global() ),
                    empty() );

        StandardUsernamePasswordCredentials c =
            CredentialsHelper.migrateCredentials( "username", "password", new URL( "http://example.org" ) );

        assertEquals( "Migrated by JIRA Plugin", c.getDescription() );
        assertThat( CredentialsProvider.lookupStores( r.jenkins ).iterator().next().getCredentials( Domain.global() ),
                    hasSize( 1 ) );
    }

    @Test
    public void testMigrateCredentialsWithExsitingCredentials()
        throws IOException
    {
        Domain domain = new Domain( "example", "test domain", Arrays.<DomainSpecification>asList(
            new HostnameSpecification( "example.org", null ) ) );
        StandardUsernamePasswordCredentials c =
            new UsernamePasswordCredentialsImpl( CredentialsScope.SYSTEM, null, null, "username", "password" );
        CredentialsProvider.lookupStores( r.jenkins ).iterator().next().addDomain( domain, c );

        StandardUsernamePasswordCredentials cred =
            CredentialsHelper.migrateCredentials( "username", "password", new URL( "http://example.org" ) );

        assertEquals( c, cred );
    }
}
{'fraction_non_alphanumeric': 0.11498810467882632, 'fraction_numerical': 0.0002643404705260375, 'mean_word_length': 4.91171875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6645727', 'n_tokens_mistral': 2144, 'n_tokens_neox': 2071, 'n_words': 394}