@Test
public void returnsNewSerProvNewWhenSerializersCached() throws IOException {

    // given
    int expectedCalls = new Random().nextInt(100) + 2;
    List<DefaultSerializerProvider> caught = new ArrayList<>();
    ExtendedObjectMapper mapper = new ExtendedObjectMapper(new JsonFactory());
    ExtendedObjectWriter writer = spy((ExtendedObjectWriter)mapper._newWriter(mapper.getSerializationConfig(), mapper.getTypeFactory().constructType(Log4jLogEvent.class), null));
    when(writer._serializerProvider()).thenAnswer((Answer<DefaultSerializerProvider>) invocationOnMock -> {
        DefaultSerializerProvider result = (DefaultSerializerProvider) invocationOnMock.callRealMethod();
        caught.add(result);
        return result;
    });
    // when
    for (int i = 0; i < expectedCalls; i++) {
        writer.writeValue((OutputStream)new ReusableByteBufOutputStream(Mockito.mock(ByteBuf.class)), Log4jLogEvent.newBuilder().build());
    }
    // then
    Assert.assertEquals(2, new HashSet<>(caught).size());
    verify(writer, Mockito.times(expectedCalls))._serializerProvider();
}