<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.Assertions;
import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.exceptions.verification.MoreThanAllowedActualInvocations;
import org.mockito.exceptions.verification.NoInteractionsWanted;
import org.mockito.exceptions.verification.TooManyActualInvocations;
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.mockito.Mockito.after;
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_with_after() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(1000, callMock);

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

    @Test
    public void should_verify_with_after_and_fail() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(40, callMock);

        // then
        Assertions.assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
            @Override
            public void call() {
                verify(mock, after(300)).oneArg('1');
            }
        }).isInstanceOf(TooManyActualInvocations.class);
    }

    @Test
    public void should_verify_with_time_x() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(50, callMock);
        async.runAfter(600, callMock);

        // then<commit_msg>Made particular test more generous<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.Assertions;
import org.assertj.core.api.ThrowableAssert;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.exceptions.verification.MoreThanAllowedActualInvocations;
import org.mockito.exceptions.verification.NoInteractionsWanted;
import org.mockito.exceptions.verification.TooManyActualInvocations;
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.mockito.Mockito.after;
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_with_after() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(1000, callMock);

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

    @Test
    public void should_verify_with_after_and_fail() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(40, callMock);

        // then
        Assertions.assertThatThrownBy(new ThrowableAssert.ThrowingCallable() {
            @Override
            public void call() {
                verify(mock, after(600)).oneArg('1');
            }
        }).isInstanceOf(TooManyActualInvocations.class);
    }

    @Test
    public void should_verify_with_time_x() {
        // given
        async.runAfter(10, callMock);
        async.runAfter(50, callMock);
        async.runAfter(600, callMock);

        // then
{'fraction_non_alphanumeric': 0.1009930276780055, 'fraction_numerical': 0.012676949080921191, 'mean_word_length': 3.1856763925729443, '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': '4232484', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1400, 'n_words': 291}