HeaderHelper { @SuppressWarnings({"unchecked"}) public static String getHeaderAsString(Object o) { HeaderDelegate headerDelegate = RuntimeDelegate.getInstance().createHeaderDelegate(o.getClass()); if (headerDelegate == null) { return o.toString(); } return headerDelegate.toString(o); } private  HeaderHelper(); static List<AcceptMediaType> createAcceptMediaTypeList(String header); static List<AcceptLanguage> createAcceptedLanguageList(String header); static List<AcceptToken> createAcceptedCharsetList(String header); static List<AcceptToken> createAcceptedEncodingList(String header); static List<Cookie> parseCookies(String cookiesString); static NewCookie parseNewCookie(String newCookieString); static Date parseDateHeader(String header); static String formatDate(Date date); static long getContentLengthLong(MultivaluedMap<String, String> httpHeaders); @SuppressWarnings({"unchecked"}) static String getHeaderAsString(Object o); static String convertToString(Collection<String> collection); static final Comparator<QualityValue> QUALITY_VALUE_COMPARATOR; }
@SuppressWarnings("unchecked") @Test public void transformsObjectToStringWithHeaderDelegate() throws Exception { RuntimeDelegate runtimeDelegate = mock(RuntimeDelegate.class); RuntimeDelegate.setInstance(runtimeDelegate); HeaderDelegate<String> headerDelegate = mock(HeaderDelegate.class); when(runtimeDelegate.createHeaderDelegate(String.class)).thenReturn(headerDelegate); when(headerDelegate.toString("foo")).thenReturn("<foo>"); assertEquals("<foo>", HeaderHelper.getHeaderAsString("foo")); }
@Test public void transformsObjectToStringWithToStringMethodWhenHeaderDelegateDoesNotPresent() throws Exception { RuntimeDelegate runtimeDelegate = mock(RuntimeDelegate.class); RuntimeDelegate.setInstance(runtimeDelegate); Object someObject = mock(Object.class); when(someObject.toString()).thenReturn("<foo>"); assertEquals("<foo>", HeaderHelper.getHeaderAsString(someObject)); }