<commit_before>package hudson.plugins.warnings.util;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.junit.Test;

/**
 *  Tests the class {@link ModuleDetector}.
 */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("SIC")
public class ModuleDetectorTest {
    /** Prefix of the path in test. */
    private static final String PATH_PREFIX = "/path/to/";
    /** Expected module name for all tests. */
    private static final String EXPECTED_MODULE = "com.avaloq.adt.core";
    /** JUnit Error message. */
    private static final String ERROR_MESSAGE = "Wrong module name detected.";

    /**
     * Checks whether we could identify a name from the file name.
     */
    @Test
    public void testTopLevelModuleName() {
        ModuleDetector detector = new ModuleDetector();

        String moduleName = detector.guessModuleName("com.avaloq.adt.core/pmd.xml", false, false);
        assertEquals(ERROR_MESSAGE, EXPECTED_MODULE, moduleName);
        moduleName = detector.guessModuleName("com.avaloq.adt.core\\pmd.xml", false, false);
        assertEquals(ERROR_MESSAGE, EXPECTED_MODULE, moduleName);
    }

    /**
     * Checks whether we could identify a maven module from a POM using the target folder.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    public void testPomNameOnTarget() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.MAVEN_POM);
        expect(factory.create(isA(String.class))).andReturn(pom);

        ModuleDetector detector = new ModuleDetector();
        detector.setFileInputStreamFactory(factory);

        replay(factory);

        assertEquals(ERROR_MESSAGE, "ADT Business Logic", detector.guessModuleName("prefix/target/suffix", true, false));

        verify(factory);
    }

    /**
     * Checks whether we could identify maven modules using the module mapping.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    public void testPomModules() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.MAVEN_POM);
        expect(factory.create(isA(String.class))).andReturn(pom);
        replay(factory);

        ModuleDetector detector = new ModuleDetector(new File("/"), factory) {
            /** {@inheritDoc} */
            @Override
            protected String[] find(final File path, final String pattern) {
                return new String[] {PATH_PREFIX + MAVEN_POM};
            }
        };

        assertEquals("Wrong module guessed", "ADT Business Logic", detector.guessModuleName(PATH_PREFIX));

        verify(factory);
    }

    /**
     * Checks whether we could identify ant projects using the module mapping.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    public void testAntModules() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.ANT_PROJECT);<commit_msg>Added SuppressWarnings.<commit_after>package hudson.plugins.warnings.util;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.junit.Test;

/**
 *  Tests the class {@link ModuleDetector}.
 */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("SIC")
public class ModuleDetectorTest {
    /** Prefix of the path in test. */
    private static final String PATH_PREFIX = "/path/to/";
    /** Expected module name for all tests. */
    private static final String EXPECTED_MODULE = "com.avaloq.adt.core";
    /** JUnit Error message. */
    private static final String ERROR_MESSAGE = "Wrong module name detected.";

    /**
     * Checks whether we could identify a name from the file name.
     */
    @Test
    public void testTopLevelModuleName() {
        ModuleDetector detector = new ModuleDetector();

        String moduleName = detector.guessModuleName("com.avaloq.adt.core/pmd.xml", false, false);
        assertEquals(ERROR_MESSAGE, EXPECTED_MODULE, moduleName);
        moduleName = detector.guessModuleName("com.avaloq.adt.core\\pmd.xml", false, false);
        assertEquals(ERROR_MESSAGE, EXPECTED_MODULE, moduleName);
    }

    /**
     * Checks whether we could identify a maven module from a POM using the target folder.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    public void testPomNameOnTarget() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.MAVEN_POM);
        expect(factory.create(isA(String.class))).andReturn(pom);

        ModuleDetector detector = new ModuleDetector();
        detector.setFileInputStreamFactory(factory);

        replay(factory);

        assertEquals(ERROR_MESSAGE, "ADT Business Logic", detector.guessModuleName("prefix/target/suffix", true, false));

        verify(factory);
    }

    /**
     * Checks whether we could identify maven modules using the module mapping.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    @edu.umd.cs.findbugs.annotations.SuppressWarnings("DMI")
    public void testPomModules() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.MAVEN_POM);
        expect(factory.create(isA(String.class))).andReturn(pom);
        replay(factory);

        ModuleDetector detector = new ModuleDetector(new File("/"), factory) {
            /** {@inheritDoc} */
            @Override
            protected String[] find(final File path, final String pattern) {
                return new String[] {PATH_PREFIX + MAVEN_POM};
            }
        };

        assertEquals("Wrong module guessed", "ADT Business Logic", detector.guessModuleName(PATH_PREFIX));

        verify(factory);
    }

    /**
     * Checks whether we could identify ant projects using the module mapping.
     *
     * @throws FileNotFoundException
     *             should never happen
     */
    @Test
    @edu.umd.cs.findbugs.annotations.SuppressWarnings("DMI")
    public void testAntModules() throws FileNotFoundException {
        FileInputStreamFactory factory = createMock(FileInputStreamFactory.class);
        InputStream pom = ModuleDetectorTest.class.getResourceAsStream(ModuleDetector.ANT_PROJECT);
{'fraction_non_alphanumeric': 0.09693443088277037, 'fraction_numerical': 0.0, 'mean_word_length': 3.0852173913043477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '7391983', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1850, 'n_words': 460}