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

package org.mockitousage.verification;

import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.exceptions.verification.MoreThanAllowedActualInvocations;
import org.mockito.exceptions.verification.TooLittleActualInvocations;
import org.mockito.junit.MockitoRule;
import org.mockitousage.IMethods;
import org.mockitoutil.Stopwatch;
import org.mockitoutil.async.AsyncTesting;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.after;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.junit.MockitoJUnit.rule;
import static org.mockitoutil.Stopwatch.createNotStarted;

public class VerificationWithAfterTest {

    @Rule public MockitoRule mockito = rule();

    @Mock private IMethods mock;

    private Runnable callMock = new Runnable() {
        public void run() {
            mock.oneArg('1');
        }
    };

    private AsyncTesting async = new AsyncTesting();
    private Stopwatch watch = createNotStarted();

    @After public void tearDown() {
        async.cleanUp();
    }

    @Test
    public void should_verify_normally_with_specific_times() {
        // given
        async.runAfter(100, callMock);

        // then
        verify(mock, after(1000).times(1)).oneArg('1');
    }

    @Test
    public void should_verify_normally_with_AtLeast() {
        // when
        async.runAfter(100, callMock);

        // then
        verify(mock, after(200).atLeast(1)).oneArg('1');
    }

    @Test
    public void should_fail_verification_with_wrong_times() {
        // when
        async.runAfter(100, callMock);

        // then
        verify(mock, times(0)).oneArg('1');

        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
            public void call() {
                verify(mock, after(200).times(2)).oneArg('1');
            }<commit_msg>Added TODOs<commit_after>/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */

package org.mockitousage.verification;

import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.exceptions.verification.MoreThanAllowedActualInvocations;
import org.mockito.exceptions.verification.TooLittleActualInvocations;
import org.mockito.junit.MockitoRule;
import org.mockitousage.IMethods;
import org.mockitoutil.Stopwatch;
import org.mockitoutil.async.AsyncTesting;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.after;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.junit.MockitoJUnit.rule;
import static org.mockitoutil.Stopwatch.createNotStarted;

public class VerificationWithAfterTest {

    @Rule public MockitoRule mockito = rule();

    @Mock private IMethods mock;

    private Runnable callMock = new Runnable() {
        public void run() {
            mock.oneArg('1');
        }
    };

    private AsyncTesting async = new AsyncTesting();
    private Stopwatch watch = createNotStarted();

    @After public void tearDown() {
        async.cleanUp();
    }

    /**

     TODO review coverage once again, it still misses some.

     -nothing + fail
     -times(2) + fail
     -atLeastOnce, atLeast(2), fail
     -atMost, fail
     -never, fail
     -only, fail

     */

    @Test
    public void should_verify_normally_with_specific_times() {
        // given
        async.runAfter(100, callMock);

        // then
        verify(mock, after(1000).times(1)).oneArg('1');
    }

    @Test
    public void should_verify_normally_with_AtLeast() {
        // when
        async.runAfter(100, callMock);

        // then
        verify(mock, after(200).atLeast(1)).oneArg('1');
    }

    @Test
    public void should_fail_verification_with_wrong_times() {
        // when
        async.runAfter(100, callMock);

        // then
        verify(mock, times(0)).oneArg('1');

        assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
            public void call() {
                verify(mock, after(200).times(2)).oneArg('1');
            }
{'fraction_non_alphanumeric': 0.1061909758656873, 'fraction_numerical': 0.01385099685204617, 'mean_word_length': 3.2214348981399468, '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': '3958770', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1432, 'n_words': 303}