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

import static org.mockito.Mockito.*;

import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.exceptions.verification.TooLittleActualInvocations;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.mockitoutil.TestBase;

@SuppressWarnings("unchecked")
public class AtLeastXVerificationTest extends TestBase {

    private List mock;
    private List mockTwo;
    
    @Before public void setup() {
        mock = Mockito.mock(List.class);
        mockTwo = Mockito.mock(List.class);
    }

    @Test
    public void shouldVerifyAtLeastOnce() throws Exception {
        mock.clear();
        mock.clear();
        
        mockTwo.add("add");

        verify(mock, atLeastOnce()).clear();
        verify(mockTwo, atLeastOnce()).add("add");
        try {
            verify(mockTwo, atLeastOnce()).add("foo");
            fail();
        } catch (WantedButNotInvoked e) {}
    }
    
    @Test(expected=WantedButNotInvoked.class)
    public void shouldFailIfMethodWasNotCalledAtAll() throws Exception {
        verify(mock, atLeastOnce()).add("foo");
    }
    
    @Test
    public void shouldVerifyAtLeastXTimes() throws Exception {
        mock.add("foo");
        mock.add("foo");
        mock.add("foo");
        
        verify(mock, atLeast(1)).add("foo");
        verify(mock, atLeast(2)).add("foo");
        verify(mock, atLeast(3)).add("foo");
    }
    
    @Test(expected=TooLittleActualInvocations.class)
    public void shouldFailOnVerifyAtLeast10WhenMethodWasInvokedOnce() throws Exception {
        mock.add("foo");

        verify(mock, atLeast(2)).add("foo");
    }
}<commit_msg>added some inOrder verification for new atLeast(x) feature<commit_after>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockitousage.verification;

import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.mockito.exceptions.verification.TooLittleActualInvocations;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.mockitoutil.TestBase;

@SuppressWarnings("unchecked")
public class AtLeastXVerificationTest extends TestBase {

    private List mock;
    private List mockTwo;
    
    @Before public void setup() {
        mock = Mockito.mock(List.class);
        mockTwo = Mockito.mock(List.class);
    }

    @Test
    public void shouldVerifyAtLeastOnce() throws Exception {
        mock.clear();
        mock.clear();
        
        mockTwo.add("add");

        verify(mock, atLeastOnce()).clear();
        verify(mockTwo, atLeastOnce()).add("add");
        try {
            verify(mockTwo, atLeastOnce()).add("foo");
            fail();
        } catch (WantedButNotInvoked e) {}
    }
    
    @Test(expected=WantedButNotInvoked.class)
    public void shouldFailIfMethodWasNotCalledAtAll() throws Exception {
        verify(mock, atLeastOnce()).add("foo");
    }
    
    @Test
    public void shouldVerifyAtLeastXTimes() throws Exception {
        mock.add("foo");
        mock.add("foo");
        mock.add("foo");
        
        verify(mock, atLeast(1)).add("foo");
        verify(mock, atLeast(2)).add("foo");
        verify(mock, atLeast(3)).add("foo");
    }
    
    @Test(expected=TooLittleActualInvocations.class)
    public void shouldFailOnVerifyAtLeast10WhenMethodWasInvokedOnce() throws Exception {
        mock.add("foo");

        verify(mock, atLeast(2)).add("foo");
    }
    
    @Test
    public void shouldVerifyInOrder() throws Exception {
        mock.add("one");
        mock.add("two");
        mock.add("three");
        
        mock.clear();
  
        InOrder inOrder = inOrder(mock);
        
        inOrder.verify(mock, atLeast(2)).add(anyString());
        inOrder.verify(mock).clear();
        verifyNoMoreInteractions(mock);
    }
    
    @Ignore
    @Test
    public void shouldFailVerificationInOrder() throws Exception {
        mock.clear();

        mock.add("one");
        mock.add("two");
        mock.add("three");
  
        InOrder inOrder = inOrder(mock);
        
        inOrder.verify(mock, atLeastOnce()).clear();

        try {
            inOrder.verify(mock, atLeast(4)).add(anyString());
            fail();
        } catch (TooLittleActualInvocations e) {}
    }
}
{'fraction_non_alphanumeric': 0.1267635741769987, 'fraction_numerical': 0.00470286447199658, 'mean_word_length': 2.822712418300654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5563136', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1407, 'n_words': 272}