Package org.mockito.internal.progress

Source Code of org.mockito.internal.progress.MockingProgressImplTest

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

package org.mockito.internal.progress;

import org.junit.Before;
import org.junit.Test;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.internal.creation.MockSettingsImpl;
import org.mockito.internal.listeners.MockingStartedListener;
import org.mockito.internal.verification.VerificationModeFactory;
import org.mockito.verification.VerificationMode;
import org.mockitoutil.TestBase;

import java.util.List;

import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class MockingProgressImplTest extends TestBase {

    private MockingProgress mockingProgress;

    @Before
    public void setup() {
        mockingProgress = new MockingProgressImpl();
    }
   
    @Test
    public void shouldStartVerificationAndPullVerificationMode() throws Exception {
        assertNull(mockingProgress.pullVerificationMode());
       
        VerificationMode mode = VerificationModeFactory.times(19);
       
        mockingProgress.verificationStarted(mode);
       
        assertSame(mode, mockingProgress.pullVerificationMode());
       
        assertNull(mockingProgress.pullVerificationMode());
    }
   
    @Test
    public void shouldCheckIfVerificationWasFinished() throws Exception {
        mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
        try {
            mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
            fail();
        } catch (MockitoException e) {}
    }

    @Test
    public void shouldNotifyListenerWhenMockingStarted() throws Exception {
        //given
        MockingStartedListener listener = mock(MockingStartedListener.class);
        mockingProgress.setListener(listener);

        //when
        mockingProgress.mockingStarted("foo", List.class);

        //then
        verify(listener).mockingStarted(eq("foo"), eq(List.class));
    }

    @Test
    public void shouldNotifyListenerSafely() throws Exception {
        //when
        mockingProgress.setListener(null);

        //then no exception is thrown:
        mockingProgress.mockingStarted(null, null);
    }
}
TOP

Related Classes of org.mockito.internal.progress.MockingProgressImplTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.