DefaultNetworkResponseParserFactory { public static void addJacksonParserIfPresent(IntegratedNetworkResponseParser.Builder builder) { if(ClassUtils.isPresent(JACKSON_2_X_CLASS_NAME)) { builder.addParser(new Jackson2NetworkResponseParser()); return; } if(ClassUtils.isPresent(JACKSON_1_X_CLASS_NAME)) { builder.addParser(new JacksonNetworkResponseParser()); return; } }  static NetworkResponseParser create(); static void addJacksonParserIfPresent(IntegratedNetworkResponseParser.Builder builder); static void addSimpleXmlParserIfPresent(IntegratedNetworkResponseParser.Builder builder);  }
@Test public void shouldAddJackson2NetworkResponserIfPresent() { given(ClassUtils.isPresent(JACKSON_2_X_CLASS_NAME)).willReturn(true); Matcher<TypedNetworkResponseParser> matcher = argMatcher(new PlainMatcher(){ @Override public boolean matches(Object item) { if (item instanceof Jackson2NetworkResponseParser) { return true; } return false; }}); DefaultNetworkResponseParserFactory.addJacksonParserIfPresent(builder); verify(builder).addParser(Matchers.argThat(matcher)); }
@Test public void shouldAddJacksonNetworkResponserIfPresent() { given(ClassUtils.isPresent(JACKSON_2_X_CLASS_NAME)).willReturn(false); given(ClassUtils.isPresent(JACKSON_1_X_CLASS_NAME)).willReturn(true); Matcher<TypedNetworkResponseParser> matcher = argMatcher(new PlainMatcher(){ @Override public boolean matches(Object item) { if (item instanceof JacksonNetworkResponseParser) { return true; } return false; }}); DefaultNetworkResponseParserFactory.addJacksonParserIfPresent(builder); verify(builder).addParser(Matchers.argThat(matcher)); }
@Test public void shouldNotAddJacksonsIfNotPresent() { given(ClassUtils.isPresent(JACKSON_2_X_CLASS_NAME)).willReturn(false); given(ClassUtils.isPresent(JACKSON_1_X_CLASS_NAME)).willReturn(false); Matcher<TypedNetworkResponseParser> matcher = argMatcher(new PlainMatcher(){ @Override public boolean matches(Object item) { if (item instanceof JacksonNetworkResponseParser) { return true; } if (item instanceof Jackson2NetworkResponseParser) { return true; } return false; }}); DefaultNetworkResponseParserFactory.addJacksonParserIfPresent(builder); verify(builder, never()).addParser(Matchers.argThat(matcher)); }