1package org.mockito.internal.session;
2
3import org.junit.After;
4import org.junit.Test;
5import org.mockito.StateMaster;
6import org.mockito.exceptions.misusing.UnfinishedMockingSessionException;
7import org.mockito.quality.Strictness;
8import org.mockitoutil.ThrowableAssert;
9
10public class DefaultMockitoSessionBuilderTest {
11
12    @After public void after() {
13        new StateMaster().clearMockitoListeners();
14    }
15
16    @Test public void creates_sessions() throws Exception {
17        //no configuration is legal
18        new DefaultMockitoSessionBuilder().startMocking().finishMocking();
19
20        //passing null to configuration is legal, default value will be used
21        new DefaultMockitoSessionBuilder().initMocks(null).startMocking().finishMocking();
22        new DefaultMockitoSessionBuilder().initMocks(null).strictness(null).startMocking().finishMocking();
23        new DefaultMockitoSessionBuilder().strictness(null).startMocking().finishMocking();
24
25        //happy path
26        new DefaultMockitoSessionBuilder().initMocks(this).startMocking().finishMocking();
27        new DefaultMockitoSessionBuilder().initMocks(new Object()).startMocking().finishMocking();
28        new DefaultMockitoSessionBuilder().strictness(Strictness.LENIENT).startMocking().finishMocking();
29    }
30
31    @Test public void requires_finish_mocking() throws Exception {
32        new DefaultMockitoSessionBuilder().startMocking();
33
34        ThrowableAssert.assertThat(new Runnable() {
35            public void run() {
36                new DefaultMockitoSessionBuilder().startMocking();
37            }
38        }).throwsException(UnfinishedMockingSessionException.class);
39    }
40}
41