### Question:
JaxbElementWrapper implements PrinterPreProcessor { @Override public Object process(Object input) { if (input instanceof JAXBElement) { return input; } if (nonNull(input.getClass().getAnnotation(XmlRootElement.class))) { return input; } return wrap(jaxb2Marshaller, input); } JaxbElementWrapper(Jaxb2Marshaller jaxb2Marshaller); @Override Object process(Object input);  }### Answer:
@Test public void processRootWithCache() { Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.class); JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller); Object input = new Root(); Object processed = jaxbElementWrapper.process(input); jaxbElementWrapper.process(input); verify(marshaller, never()).getContextPath(); verify(marshaller, never()).getClassesToBeBound(); assertThat(processed, is(input)); }
@Test public void processEmptyWithWrapperMethodCache() { Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.class); when(marshaller.getClassesToBeBound()).thenReturn(new Class[]{}); JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller); Object input = new Empty(); Object processed = jaxbElementWrapper.process(input); jaxbElementWrapper.process(input); verify(marshaller).getContextPath(); verify(marshaller).getClassesToBeBound(); assertThat(processed, is(input)); }
@Test public void processEmptyWithRegistry() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(Registry.class); JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller); Object input = new Empty(); Object processed = jaxbElementWrapper.process(input); assertTrue(processed instanceof JAXBElement); assertThat(((JAXBElement) processed).getValue(), is(input)); }
@Test public void processEmptyRegistry() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(EmptyRegistry.class); JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller); Object input = new Empty(); Object processed = jaxbElementWrapper.process(input); assertThat(processed, is(input)); }
@Test public void processJaxbElement() { Jaxb2Marshaller marshaller = mock(Jaxb2Marshaller.class); JaxbElementWrapper jaxbElementWrapper = new JaxbElementWrapper(marshaller); Object input = new JAXBElement<>(new QName("localPart"), Empty.class, new Empty()); Object processed = jaxbElementWrapper.process(input); verify(marshaller, never()).getContextPath(); verify(marshaller, never()).getClassesToBeBound(); assertThat(processed, is(input)); }