Log hierarchy in Logback

Log hierarchy in Logback is based on the log names. That is a characteristic that makes lots of interesting and handy features possible. The post looks into a couple of examples how that works. How named log hierarchy works According to the logger documentation, a logger is said to be an ancestor of another logger if its name followed by a …

Mock final classes with Mockito

One of the standard Mockito related questions I’ve come across is online is “Can we mock final classes with Mockito?”. The answer to this question since Mockito 2 was introduced is “Yes, we can.”. Example code This is the test I would like to be able to run: @ExtendWith(MockitoExtension.class) class PersonTest { @Mock PinProvider pinProvider; @Test public void shouldCreatePersonWithCorrectPin() { …

Using Mockito with JUnit 5

Since version 2.16.3 Mockito has official support for Junit5. Using Mockito with JUnit now is even easier than before. Previously I kept forgetting what rule I was supposed to use for injecting the mocks, and how I set the strictness again? Plus the extra field in each test class! Mockito with JUnit 5 example The newly introduced extension is not part of …