<commit_before>package sortpom.util;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import sortpom.parameter.PluginParameters;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author bjorn
 * @since 2013-08-16
 */
public class FileUtilTest {
    @Test
    public void defaultSortOrderFromFileShouldWork() throws Exception {
        FileUtil fileUtil = createFileUtil("Attribute_expected.xml");

        String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml();
        assertThat(defaultSortOrderXml, startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
                "<projec"));
    }

    @Test
    public void defaultSortOrderFromNonExistingShouldThrowException() {
        FileUtil fileUtil = createFileUtil("zzz_Attribute_expected.xml");

        final Executable testMethod = () -> fileUtil.getDefaultSortOrderXml();

        final IOException thrown = assertThrows(IOException.class, testMethod);

        assertThat(thrown.getMessage(), startsWith("Could not find"));
        assertThat(thrown.getMessage(), endsWith("or zzz_Attribute_expected.xml in classpath"));
    }

    @Test
    public void defaultSortOrderFromUrlShouldWork() throws IOException {
        FileUtil fileUtil = createFileUtil("https://en.wikipedia.org/wiki/Sweden");

        try {
        String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml();
            assertThat(defaultSortOrderXml, containsString("Sverige"));
        } catch (UnknownHostException e) {
            // This is ok, we were not online when the test was perfomed
            // Which actually makes this test a bit pointless :-(
        }
    }

    @Test
    @Disabled
    public void defaultSortOrderFromNonExistingHostShouldThrowException() {
        FileUtil fileUtil = createFileUtil("http://jgerwzuujy.fjrmzaxklj.zfgmqavbhp/licenses/BSD-3-Clause");

        final Executable testMethod = () -> fileUtil.getDefaultSortOrderXml();

        final UnknownHostException thrown = assertThrows(UnknownHostException.class, testMethod);

        assertThat(thrown.getMessage(), is("jgerwzuujy.fjrmzaxklj.zfgmqavbhp"));
    }
<commit_msg>@Disabled comment as to why test disabled<commit_after>package sortpom.util;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import sortpom.parameter.PluginParameters;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

/**
 * @author bjorn
 * @since 2013-08-16
 */
public class FileUtilTest {
    @Test
    public void defaultSortOrderFromFileShouldWork() throws Exception {
        FileUtil fileUtil = createFileUtil("Attribute_expected.xml");

        String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml();
        assertThat(defaultSortOrderXml, startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
                "<projec"));
    }

    @Test
    public void defaultSortOrderFromNonExistingShouldThrowException() {
        FileUtil fileUtil = createFileUtil("zzz_Attribute_expected.xml");

        final Executable testMethod = () -> fileUtil.getDefaultSortOrderXml();

        final IOException thrown = assertThrows(IOException.class, testMethod);

        assertThat(thrown.getMessage(), startsWith("Could not find"));
        assertThat(thrown.getMessage(), endsWith("or zzz_Attribute_expected.xml in classpath"));
    }

    @Test
    public void defaultSortOrderFromUrlShouldWork() throws IOException {
        FileUtil fileUtil = createFileUtil("https://en.wikipedia.org/wiki/Sweden");

        try {
        String defaultSortOrderXml = fileUtil.getDefaultSortOrderXml();
            assertThat(defaultSortOrderXml, containsString("Sverige"));
        } catch (UnknownHostException e) {
            // This is ok, we were not online when the test was perfomed
            // Which actually makes this test a bit pointless :-(
        }
    }

    @Test
    @Disabled("Test was failing in 2.11.0 branch so disabled")
    public void defaultSortOrderFromNonExistingHostShouldThrowException() {
        FileUtil fileUtil = createFileUtil("http://jgerwzuujy.fjrmzaxklj.zfgmqavbhp/licenses/BSD-3-Clause");

        final Executable testMethod = () -> fileUtil.getDefaultSortOrderXml();

        final UnknownHostException thrown = assertThrows(UnknownHostException.class, testMethod);

        assertThat(thrown.getMessage(), is("jgerwzuujy.fjrmzaxklj.zfgmqavbhp"));
    }

{'fraction_non_alphanumeric': 0.10258832420177592, 'fraction_numerical': 0.005290005667863216, 'mean_word_length': 3.920074349442379, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 2, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '524723', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1491, 'n_words': 299}