BAEL-3231: Add usage example for MockitoJUnit.rule() (#8304)

This commit is contained in:
kwoyke 2019-12-05 17:19:46 +01:00 committed by Grzegorz Piwowarek
parent ac8d8b824f
commit 2dcfc0efb7
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package com.baeldung.mockito;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
public class MockitoInitWithMockitoJUnitRuleUnitTest {
@Rule
public MockitoRule initRule = MockitoJUnit.rule();
@Mock
private List<String> mockedList;
@Test
public void whenUsingMockitoJUnitRule_thenMocksInitialized() {
when(mockedList.size()).thenReturn(41);
assertThat(mockedList.size()).isEqualTo(41);
}
}