EntityTagHeaderDelegate implements RuntimeDelegate.HeaderDelegate<EntityTag> { @Override public String toString(EntityTag entityTag) { if (entityTag == null) { throw new IllegalArgumentException(); } StringBuilder sb = new StringBuilder(); if (entityTag.isWeak()) { sb.append('W').append('/'); } sb.append('"'); HeaderHelper.appendEscapeQuote(sb, entityTag.getValue()); sb.append('"'); return sb.toString(); }  @Override EntityTag fromString(String header); @Override String toString(EntityTag entityTag);  }
@Test public void testToStringSimple() { EntityTag entityTag = new EntityTag("test", false); assertEquals("\"test\"", entityTagHeaderDelegate.toString(entityTag)); }
@Test public void testToStringSimpleWeak() { EntityTag entityTag = new EntityTag("test", true); assertEquals("W/\"test\"", entityTagHeaderDelegate.toString(entityTag)); }
@Test public void testToStringWithQuotedString() { EntityTag entityTag = new EntityTag("test \"test\"", false); assertEquals("\"test \\\"test\\\"\"", entityTagHeaderDelegate.toString(entityTag)); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenEntityTagIsNull() throws Exception { entityTagHeaderDelegate.toString(null); }