JAVA-16612: Mock Final Classes and Methods with Mockito article; MockMaker improvement (#13890)
This commit is contained in:
parent
f5910afe6f
commit
87e4bc434f
|
@ -57,7 +57,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<spring-framework.version>5.3.20</spring-framework.version>
|
<spring-framework.version>5.3.20</spring-framework.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<mockito.version>4.6.1</mockito.version>
|
<mockito.version>4.8.0</mockito.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -3,8 +3,10 @@ package com.baeldung.mockito;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.withSettings;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.MockMakers;
|
||||||
|
|
||||||
class MockFinalsUnitTest {
|
class MockFinalsUnitTest {
|
||||||
|
|
||||||
|
@ -29,4 +31,14 @@ class MockFinalsUnitTest {
|
||||||
|
|
||||||
assertThat(mock.size()).isNotEqualTo(finalList.size());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue