• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito;
7 
8 import static org.assertj.core.api.Assertions.assertThat;
9 import static org.mockito.Mockito.times;
10 import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;
11 
12 import java.util.List;
13 import org.junit.Test;
14 import org.mockito.exceptions.misusing.NotAMockException;
15 import org.mockito.internal.creation.MockSettingsImpl;
16 
17 @SuppressWarnings("unchecked")
18 public class MockitoTest {
19 
20     @Test
shouldRemoveStubbableFromProgressAfterStubbing()21     public void shouldRemoveStubbableFromProgressAfterStubbing() {
22         List mock = Mockito.mock(List.class);
23         Mockito.when(mock.add("test")).thenReturn(true);
24         //TODO Consider to move to separate test
25         assertThat(mockingProgress().pullOngoingStubbing()).isNull();
26     }
27 
28     @Test(expected=NotAMockException.class)
shouldValidateMockWhenVerifying()29     public void shouldValidateMockWhenVerifying() {
30         Mockito.verify("notMock");
31     }
32 
33     @Test(expected=NotAMockException.class)
shouldValidateMockWhenVerifyingWithExpectedNumberOfInvocations()34     public void shouldValidateMockWhenVerifyingWithExpectedNumberOfInvocations() {
35         Mockito.verify("notMock", times(19));
36     }
37 
38     @Test(expected=NotAMockException.class)
shouldValidateMockWhenVerifyingNoMoreInteractions()39     public void shouldValidateMockWhenVerifyingNoMoreInteractions() {
40         Mockito.verifyNoMoreInteractions("notMock");
41     }
42 
43     @Test(expected=NotAMockException.class)
shouldValidateMockWhenVerifyingZeroInteractions()44     public void shouldValidateMockWhenVerifyingZeroInteractions() {
45         Mockito.verifyZeroInteractions("notMock");
46     }
47 
48     @Test(expected=NotAMockException.class)
shouldValidateMockWhenCreatingInOrderObject()49     public void shouldValidateMockWhenCreatingInOrderObject() {
50         Mockito.inOrder("notMock");
51     }
52 
53     @Test
shouldStartingMockSettingsContainDefaultBehavior()54     public void shouldStartingMockSettingsContainDefaultBehavior() {
55         //when
56         MockSettingsImpl<?> settings = (MockSettingsImpl<?>) Mockito.withSettings();
57 
58         //then
59         assertThat(Mockito.RETURNS_DEFAULTS).isEqualTo(settings.getDefaultAnswer());
60     }
61 
62 }
63