EntityTagHeaderDelegate implements RuntimeDelegate.HeaderDelegate<EntityTag> { @Override public EntityTag fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } boolean isWeak = header.startsWith("W/"); String value; if (isWeak) { value = cutWeakPrefix(header); } else { value = header; } value = value.substring(1, value.length() - 1); value = HeaderHelper.removeQuoteEscapes(value); return new EntityTag(value, isWeak); }  @Override EntityTag fromString(String header); @Override String toString(EntityTag entityTag);  }
@Test public void parsesString() { EntityTag entityTag = entityTagHeaderDelegate.fromString("\"test\""); assertFalse(entityTag.isWeak()); assertEquals("test", entityTag.getValue()); }
@Test public void parsesStringQuoted() { EntityTag entityTag = entityTagHeaderDelegate.fromString("\"test \\\"test\\\"\""); assertFalse(entityTag.isWeak()); assertEquals("test \"test\"", entityTag.getValue()); }
@Test public void parsesStringWeak() { EntityTag entityTag = entityTagHeaderDelegate.fromString("W/\"test\""); assertTrue(entityTag.isWeak()); assertEquals("test", entityTag.getValue()); }
@Test public void parsesStringQuotedWeak() { EntityTag entityTag = entityTagHeaderDelegate.fromString("W/\"test \\\"test\\\"\""); assertTrue(entityTag.isWeak()); assertEquals("test \"test\"", entityTag.getValue()); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenEntityTagHeaderIsNull() throws Exception { entityTagHeaderDelegate.fromString(null); }