JAVA-16612: Mock Final Classes and Methods with Mockito article; MockMaker improvement (#13890)

This commit is contained in:
Bipin kumar 2023-05-03 15:06:25 +05:30 committed by GitHub
parent f5910afe6f
commit 87e4bc434f
2 changed files with 13 additions and 1 deletions

View File

@ -57,7 +57,7 @@
<properties>
<spring-framework.version>5.3.20</spring-framework.version>
<!-- testing -->
<mockito.version>4.6.1</mockito.version>
<mockito.version>4.8.0</mockito.version>
</properties>
</project>

View File

@ -3,8 +3,10 @@ package com.baeldung.mockito;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
import org.junit.jupiter.api.Test;
import org.mockito.MockMakers;
class MockFinalsUnitTest {
@ -29,4 +31,14 @@ class MockFinalsUnitTest {
assertThat(mock.size()).isNotEqualTo(finalList.size());
}
@Test
public void whenMockFinalMethodMockWorks_withInlineMockMaker() {
MyList myList = new MyList();
MyList mock = mock(MyList.class, withSettings().mockMaker(MockMakers.INLINE));
when(mock.finalMethod()).thenReturn(1);
assertThat(mock.finalMethod()).isNotEqualTo(myList.finalMethod());
}
}