ChildConverterContextInjector implements PostCompileProcessor<ILoggingEvent> { @Override public void process(Context context, Converter<ILoggingEvent> head) { inject(context, head, false); }  @Override void process(Context context, Converter<ILoggingEvent> head);  }
@Test public void doesNotInjectContextInSingleConverter() throws Exception { DynamicConverter<ILoggingEvent> converter = new ContextAwareTestConverter(); processor.process(Mockito.mock(Context.class), converter); assertNull("No context should be set.", converter.getContext()); }
@Test public void injectsContextInSingleChild() throws Exception { CompositeTestConverter parent = new CompositeTestConverter(); ContextAwareTestConverter child = new ContextAwareTestConverter(); parent.setChildConverter(child); Context context = Mockito.mock(Context.class); processor.process(context, parent); assertThat(child.getContext(), is(sameInstance(context))); }
@Test public void followsChainToConverterWithChild() throws Exception { SimpleTestConverter start = new SimpleTestConverter(); CompositeTestConverter parent = new CompositeTestConverter(); ContextAwareTestConverter child = new ContextAwareTestConverter(); start.setNext(parent); parent.setChildConverter(child); Context context = Mockito.mock(Context.class); processor.process(context, parent); assertThat(child.getContext(), is(sameInstance(context))); }
@Test public void injectsIntoChildrenOfChildren() throws Exception { CompositeTestConverter grandParent = new CompositeTestConverter(); CompositeTestConverter parent = new CompositeTestConverter(); ContextAwareTestConverter child = new ContextAwareTestConverter(); grandParent.setChildConverter(parent); parent.setChildConverter(child); Context context = Mockito.mock(Context.class); processor.process(context, grandParent); assertThat(parent.getContext(), is(sameInstance(context))); assertThat(child.getContext(), is(sameInstance(context))); }
@Test public void injectsIntoFullChildChain() throws Exception { CompositeTestConverter parent = new CompositeTestConverter(); SimpleTestConverter child1 = new SimpleTestConverter(); ContextAwareTestConverter child2 = new ContextAwareTestConverter(); parent.setChildConverter(child1); child1.setNext(child2); Context context = Mockito.mock(Context.class); processor.process(context, parent); assertThat(child2.getContext(), is(sameInstance(context))); }