<commit_before>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.verification;

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.internal.progress.VerificationModeImpl.*;

import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;
import org.mockito.RequiresValidState;
import org.mockito.exceptions.Reporter;
import org.mockito.internal.invocation.Invocation;
import org.mockito.internal.invocation.InvocationBuilder;
import org.mockito.internal.invocation.InvocationMatcher;
import org.mockito.internal.progress.VerificationModeBuilder;

public class NumberOfInvocationsInOrderVerifierTest extends RequiresValidState {

    private NumberOfInvocationsInOrderVerifier verifier;
    private Reporter reporter;
    private InvocationMatcher wanted;
    private LinkedList<Invocation> invocations;
    private InvocationsFinderStub finderStub;
    
    @Before
    public void setup() {
        reporter = new Reporter();
        finderStub = new InvocationsFinderStub();
        verifier = new NumberOfInvocationsInOrderVerifier(finderStub, reporter);
        
        wanted = new InvocationBuilder().toInvocationMatcher();
        invocations = new LinkedList<Invocation>(asList(new InvocationBuilder().toInvocation()));
    }
    
    @Test
    public void shouldNeverVerifyIfModeIsNotInOrder() throws Exception {
        verifier.verify(null, wanted, atLeastOnce());
    }
    
    @Test
    public void shouldPassIfWantedIsZeroAndMatchingChunkIsEmpty() throws Exception {
        assertTrue(finderStub.validMatchingChunkToReturn.isEmpty());
        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(0).inOrder());
    }
    
    @Test
    public void shouldPassIfChunkMatches() throws Exception {
        finderStub.validMatchingChunkToReturn.add(wanted.getInvocation());
        
        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
    }
    
//    @Test
//    public void shouldReportTooLittleInvocations() throws Exception {
//        Invocation first = new InvocationBuilder().toInvocation();
//        Invocation second = new InvocationBuilder().toInvocation();
//        finderStub.allMatchingUnverifiedChunksToReturn.addAll(asList(first, second)); 
//        
//        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(4).inOrder());
//        
//        assertEquals(4, reporterStub.wantedCount);
//        assertEquals(2, reporterStub.actualCount);
//        assertSame(second.getStackTrace(), reporterStub.lastActualStackTrace);
//        assertEquals(wanted.toString(), reporterStub.wanted);
//    }
//    
//    @Test
//    public void shouldReportTooManyInvocations() throws Exception {
//        Invocation first = new InvocationBuilder().toInvocation();
//        Invocation second = new InvocationBuilder().toInvocation();
//        finderStub.allMatchingUnverifiedChunksToReturn.addAll(asList(first, second)); 
//        
//        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
//        
//        assertEquals(1, reporterStub.wantedCount);
//        assertEquals(2, reporterStub.actualCount);
//        assertSame(second.getStackTrace(), reporterStub.firstUndesired);
//        assertEquals(wanted.toString(), reporterStub.wanted);
//    }
//    
//    @Test
//    public void shouldMarkInvocationsAsVerified() throws Exception {
//        Invocation invocation = new InvocationBuilder().toInvocation();
//        finderStub.allMatchingUnverifiedChunksToReturn.add(invocation);
//        assertFalse(invocation.isVerifiedInOrder());
//        
//        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
//        
//        assertTrue(invocation.isVerifiedInOrder());
//    }

//    class ReporterStub extends Reporter {
//        private HasStackTrace lastActualStackTrace;
//        private int actualCount;
//        private int wantedCount;
//        private HasStackTrace firstUndesired;
//        private String wanted;
//
//        @Override public void tooLittleActualInvocationsInOrder(int wantedCount, int actualCount, String wanted, HasStackTrace lastActualStackTrace) {
//            this.wantedCount = wantedCount;
//            this.actualCount = actualCount;
//            this.wanted = wanted;
//            this.lastActualStackTrace = lastActualStackTrace;
//        }
//        
//        @Override public void tooManyActualInvocationsInOrder(int wantedCount, int actualCount, String wanted, HasStackTrace firstUndesired) {
//            this.wantedCount = wantedCount;
//            this.actualCount = actualCount;
//            this.wanted = wanted;
//            this.firstUndesired = firstUndesired;
//        }
//    }
}<commit_msg>enabled another test in an effort to finish implementing relaxed verification in order<commit_after>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.verification;

import static java.util.Arrays.*;
import static org.mockito.util.ExtraMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.internal.progress.VerificationModeImpl.*;

import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;
import org.mockito.RequiresValidState;
import org.mockito.exceptions.Reporter;
import org.mockito.exceptions.verification.VerifcationInOrderFailed;
import org.mockito.internal.invocation.Invocation;
import org.mockito.internal.invocation.InvocationBuilder;
import org.mockito.internal.invocation.InvocationMatcher;
import org.mockito.internal.progress.VerificationModeBuilder;

public class NumberOfInvocationsInOrderVerifierTest extends RequiresValidState {

    private NumberOfInvocationsInOrderVerifier verifier;
    private Reporter reporter;
    private InvocationMatcher wanted;
    private LinkedList<Invocation> invocations;
    private InvocationsFinderStub finderStub;
    
    @Before
    public void setup() {
        reporter = new Reporter();
        finderStub = new InvocationsFinderStub();
        verifier = new NumberOfInvocationsInOrderVerifier(finderStub, reporter);
        
        wanted = new InvocationBuilder().toInvocationMatcher();
        invocations = new LinkedList<Invocation>(asList(new InvocationBuilder().toInvocation()));
    }
    
    @Test
    public void shouldNeverVerifyIfModeIsNotInOrder() throws Exception {
        verifier.verify(null, wanted, atLeastOnce());
    }
    
    @Test
    public void shouldPassIfWantedIsZeroAndMatchingChunkIsEmpty() throws Exception {
        assertTrue(finderStub.validMatchingChunkToReturn.isEmpty());
        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(0).inOrder());
    }
    
    @Test
    public void shouldPassIfChunkMatches() throws Exception {
        finderStub.validMatchingChunkToReturn.add(wanted.getInvocation());
        
        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
    }
    
    @Test
    public void shouldReportTooLittleInvocations() throws Exception {
        Invocation first = new InvocationBuilder().toInvocation();
        Invocation second = new InvocationBuilder().toInvocation();
        finderStub.validMatchingChunkToReturn.addAll(asList(first, second)); 
        
        try {
            verifier.verify(invocations, wanted, new VerificationModeBuilder().times(4).inOrder());
            fail();
        } catch (VerifcationInOrderFailed e) {
            assertThat(e, messageContains("Wanted 4 times but was 2"));
        };
    }
    
    @Test
    public void shouldReportTooManyInvocations() throws Exception {
        Invocation first = new InvocationBuilder().toInvocation();
        Invocation second = new InvocationBuilder().toInvocation();
        finderStub.validMatchingChunkToReturn.addAll(asList(first, second)); 
        
        try {
            verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
            fail();
        } catch (VerifcationInOrderFailed e) {
            assertThat(e, messageContains("Wanted 1 time but was 2"));
        };
    }
    
    @Test
    public void shouldMarkAsVerifiedInOrder() throws Exception {
        Invocation invocation = new InvocationBuilder().toInvocation();
        assertFalse(invocation.isVerifiedInOrder());
        finderStub.validMatchingChunkToReturn.addAll(asList(invocation)); 
        
        verifier.verify(invocations, wanted, new VerificationModeBuilder().times(1).inOrder());
        
        assertTrue(invocation.isVerifiedInOrder());
    }
}
{'fraction_non_alphanumeric': 0.10009099181073704, 'fraction_numerical': 0.002957233848953594, 'mean_word_length': 3.3986993496748372, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2896680', 'n_tokens_mistral': 2347, 'n_tokens_neox': 2304, 'n_words': 466}