diff --git a/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoInitWithMockitoJUnitRuleUnitTest.java b/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoInitWithMockitoJUnitRuleUnitTest.java new file mode 100644 index 0000000000..1bbe13ec84 --- /dev/null +++ b/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoInitWithMockitoJUnitRuleUnitTest.java @@ -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 mockedList; + + @Test + public void whenUsingMockitoJUnitRule_thenMocksInitialized() { + when(mockedList.size()).thenReturn(41); + + assertThat(mockedList.size()).isEqualTo(41); + } +}