<commit_before>package hudson.plugins.analysis.core;

import static junit.framework.Assert.*;
import static org.mockito.Mockito.*;

import java.util.NoSuchElementException;

import org.junit.Test;

import hudson.model.AbstractBuild;

import hudson.plugins.analysis.util.model.AnnotationContainer;

/**
 * Tests the class {@link BuildHistory}.
 *
 * @author <NAME>
 */
public class BuildHistoryTest {
    /**
     * Verifies that we have no results for the first build.
     *
     * @throws Exception the exception
     */
    @Test(expected = NoSuchElementException.class)
    public void testNoPreviousResult() throws Exception {
        BuildHistory history = createHistory(mock(AbstractBuild.class));

        assertFalse("Build has a previous result", history.hasPreviousResult());
        assertEquals("Build has wrong reference annotations", 0,
                history.getReferenceAnnotations().getNumberOfAnnotations());

        history.getPreviousResult();
    }

    /**
     * Verifies that we find the correct results for the following constellation.
     * <ol>
     * <li>Build with result</li>
     * <li>Build with no result</li>
     * <li>Baseline</li>
     * </ol>
     * @throws Exception the exception
     */
    @Test
    @SuppressWarnings("unchecked")
    public void testHasPreviousResult() throws Exception {
        AbstractBuild withResult = mock(AbstractBuild.class);
        AbstractBuild noResult = mock(AbstractBuild.class);
        AbstractBuild baseline = mock(AbstractBuild.class);
        when(baseline.getPreviousBuild()).thenReturn(noResult);
        when(noResult.getPreviousBuild()).thenReturn(withResult);

        ResultAction action = mock(ResultAction.class);
        when(withResult.getAction(ResultAction.class)).thenReturn(action);
        BuildResult result = mock(BuildResult.class);
        when(action.getResult()).thenReturn(result);
        AnnotationContainer container = mock(AnnotationContainer.class);
        when(result.getContainer()).thenReturn(container);
        BuildHistory history = createHistory(baseline);

        assertTrue("Build has no previous result", history.hasPreviousResult());
        assertSame("Build has wrong previous result", result, history.getPreviousResult());
        assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
    }

    /**
     * Verifies that we find the correct results for the following constellation.
     * <ol>
     * <li>Build with result, build result = SUCCESS</li>
     * <li>Build with no result</li>
     * <li>Build with result, build result = FAILURE</li>
     * <li>Build with no result</li>
     * <li>Baseline</li>
     * </ol>
     * @throws Exception the exception
     */
    @SuppressWarnings("unchecked")
    @Test
    public void testHasReferenceResult() throws Exception {
        AbstractBuild withSuccessResult = mock(AbstractBuild.class);
        AbstractBuild noResult2 = mock(AbstractBuild.class);
        AbstractBuild withFailureResult = mock(AbstractBuild.class);
        AbstractBuild noResult1 = mock(AbstractBuild.class);
        AbstractBuild baseline = mock(AbstractBuild.class);
        when(baseline.getPreviousBuild()).thenReturn(noResult1);
        when(noResult1.getPreviousBuild()).thenReturn(withFailureResult);
        when(withFailureResult.getPreviousBuild()).thenReturn(noResult2);
        when(noResult2.getPreviousBuild()).thenReturn(withSuccessResult);

        ResultAction failureAction = mock(ResultAction.class);
        when(withFailureResult.getAction(ResultAction.class)).thenReturn(failureAction);
        when(failureAction.isSuccessful()).thenReturn(false);
        BuildResult failureResult = mock(BuildResult.class);
        when(failureAction.getResult()).thenReturn(failureResult);

        ResultAction successAction = mock(ResultAction.class);
        when(withSuccessResult.getAction(ResultAction.class)).thenReturn(successAction);
        when(successAction.isSuccessful()).thenReturn(true);
        BuildResult successResult = mock(BuildResult.class);
        AnnotationContainer container = mock(AnnotationContainer.class);
        when(successResult.getContainer()).thenReturn(container);
        when(successAction.getResult()).thenReturn(successResult);

        BuildHistory history = createHistory(baseline);

        assertTrue("Build has no previous result", history.hasPreviousResult());
        assertSame("Build has wrong previous result", failureResult, history.getPreviousResult());
        assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
    }

    /**
     * Factory method to create a build history under test.
     *
     * @param baseline
     *            the build to start with
     * @return the build history under test
     */
    @SuppressWarnings("unchecked")
    private BuildHistory createHistory(final AbstractBuild<?, ?> baseline) {
        return new BuildHistory(baseline, (Class<? extends ResultAction<? extends BuildResult>>)ResultAction.class);
    }
}
<commit_msg>Fixed generics problem.<commit_after>package hudson.plugins.analysis.core;

import static junit.framework.Assert.*;
import static org.mockito.Mockito.*;

import java.util.NoSuchElementException;

import org.junit.Test;

import hudson.model.AbstractBuild;

import hudson.plugins.analysis.util.model.AnnotationContainer;

/**
 * Tests the class {@link BuildHistory}.
 *
 * @author <NAME>
 */
public class BuildHistoryTest {
    /**
     * Verifies that we have no results for the first build.
     *
     * @throws Exception the exception
     */
    @Test(expected = NoSuchElementException.class)
    public void testNoPreviousResult() throws Exception {
        BuildHistory history = createHistory(mock(AbstractBuild.class));

        assertFalse("Build has a previous result", history.hasPreviousResult());
        assertEquals("Build has wrong reference annotations", 0,
                history.getReferenceAnnotations().getNumberOfAnnotations());

        history.getPreviousResult();
    }

    /**
     * Verifies that we find the correct results for the following constellation.
     * <ol>
     * <li>Build with result</li>
     * <li>Build with no result</li>
     * <li>Baseline</li>
     * </ol>
     * @throws Exception the exception
     */
    @Test
    @SuppressWarnings("unchecked")
    public void testHasPreviousResult() throws Exception {
        AbstractBuild withResult = mock(AbstractBuild.class);
        AbstractBuild noResult = mock(AbstractBuild.class);
        AbstractBuild baseline = mock(AbstractBuild.class);
        when(baseline.getPreviousBuild()).thenReturn(noResult);
        when(noResult.getPreviousBuild()).thenReturn(withResult);

        TestResultAction action = mock(TestResultAction.class);
        when(withResult.getAction(TestResultAction.class)).thenReturn(action);
        BuildResult result = mock(BuildResult.class);
        when(action.getResult()).thenReturn(result);
        AnnotationContainer container = mock(AnnotationContainer.class);
        when(result.getContainer()).thenReturn(container);
        BuildHistory history = createHistory(baseline);

        assertTrue("Build has no previous result", history.hasPreviousResult());
        assertSame("Build has wrong previous result", result, history.getPreviousResult());
        assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
    }

    /**
     * Verifies that we find the correct results for the following constellation.
     * <ol>
     * <li>Build with result, build result = SUCCESS</li>
     * <li>Build with no result</li>
     * <li>Build with result, build result = FAILURE</li>
     * <li>Build with no result</li>
     * <li>Baseline</li>
     * </ol>
     * @throws Exception the exception
     */
    @SuppressWarnings("unchecked")
    @Test
    public void testHasReferenceResult() throws Exception {
        AbstractBuild withSuccessResult = mock(AbstractBuild.class);
        AbstractBuild noResult2 = mock(AbstractBuild.class);
        AbstractBuild withFailureResult = mock(AbstractBuild.class);
        AbstractBuild noResult1 = mock(AbstractBuild.class);
        AbstractBuild baseline = mock(AbstractBuild.class);
        when(baseline.getPreviousBuild()).thenReturn(noResult1);
        when(noResult1.getPreviousBuild()).thenReturn(withFailureResult);
        when(withFailureResult.getPreviousBuild()).thenReturn(noResult2);
        when(noResult2.getPreviousBuild()).thenReturn(withSuccessResult);

        TestResultAction failureAction = mock(TestResultAction.class);
        when(withFailureResult.getAction(TestResultAction.class)).thenReturn(failureAction);
        when(failureAction.isSuccessful()).thenReturn(false);
        BuildResult failureResult = mock(BuildResult.class);
        when(failureAction.getResult()).thenReturn(failureResult);

        TestResultAction successAction = mock(TestResultAction.class);
        when(withSuccessResult.getAction(TestResultAction.class)).thenReturn(successAction);
        when(successAction.isSuccessful()).thenReturn(true);
        BuildResult successResult = mock(BuildResult.class);
        AnnotationContainer container = mock(AnnotationContainer.class);
        when(successResult.getContainer()).thenReturn(container);
        when(successAction.getResult()).thenReturn(successResult);

        BuildHistory history = createHistory(baseline);

        assertTrue("Build has no previous result", history.hasPreviousResult());
        assertSame("Build has wrong previous result", failureResult, history.getPreviousResult());
        assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
    }

    /**
     * Factory method to create a build history under test.
     *
     * @param baseline
     *            the build to start with
     * @return the build history under test
     */
    private BuildHistory createHistory(final AbstractBuild<?, ?> baseline) {
        return new BuildHistory(baseline, TestResultAction.class);
    }

    /**
     * Action used in tests.
     */
    abstract static class TestResultAction implements ResultAction<BuildResult> {
        // empty
    }
}

{'fraction_non_alphanumeric': 0.10527859237536658, 'fraction_numerical': 0.0013685239491691105, 'mean_word_length': 3.6085585585585584, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, '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': '5935866', 'n_tokens_mistral': 2561, 'n_tokens_neox': 2515, 'n_words': 582}