@Test public void testSerializeEtag() { RuntimeDelegate rd = RuntimeDelegate.getInstance(); HeaderDelegate<EntityTag> entityTagHeaderDelegate = rd.createHeaderDelegate(EntityTag.class); if (entityTagHeaderDelegate == null) { fail("EntityTag header delegate is not regestered in RuntimeDelegateImpl"); } String entityTagString = "12321-\"12321-123123"; String expectedEntityTagString = "\"" + "12321-\\\"12321-123123" + "\""; EntityTag weakETag = new EntityTag(entityTagString, true); String weakETagString = entityTagHeaderDelegate.toString(weakETag); assertEquals("W/" + expectedEntityTagString, weakETagString); EntityTag strongETag = new EntityTag(entityTagString, false); String strongETagString = entityTagHeaderDelegate.toString(strongETag); assertEquals(expectedEntityTagString, strongETagString); try { EntityTag eTag = null; entityTagHeaderDelegate.toString(eTag); fail("EntityTag is null - IllegalArgumentException must be thrown"); } catch (IllegalArgumentException e) { } }
public String toString(EntityTag eTag) { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } StringBuilder builder = new StringBuilder(); if (eTag.isWeak()) { builder.append("W/"); } builder.append('"'); String value = eTag.getValue(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '"') builder.append('\\'); builder.append(c); } builder.append('"'); return builder.toString(); }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public String toString(EntityTag eTag) { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } StringBuilder builder = new StringBuilder(); if (eTag.isWeak()) { builder.append("W/"); } builder.append('"'); String value = eTag.getValue(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '"') builder.append('\\'); builder.append(c); } builder.append('"'); return builder.toString(); } }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public String toString(EntityTag eTag) { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } StringBuilder builder = new StringBuilder(); if (eTag.isWeak()) { builder.append("W/"); } builder.append('"'); String value = eTag.getValue(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '"') builder.append('\\'); builder.append(c); } builder.append('"'); return builder.toString(); }  }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public String toString(EntityTag eTag) { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } StringBuilder builder = new StringBuilder(); if (eTag.isWeak()) { builder.append("W/"); } builder.append('"'); String value = eTag.getValue(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '"') builder.append('\\'); builder.append(c); } builder.append('"'); return builder.toString(); }  EntityTag fromString(String eTag); String toString(EntityTag eTag); }
EntityTagHeaderDelegate implements HeaderDelegate<EntityTag> { public String toString(EntityTag eTag) { if (eTag == null) { throw new IllegalArgumentException(Messages.getMessage("variableIsNull", "eTag")); } StringBuilder builder = new StringBuilder(); if (eTag.isWeak()) { builder.append("W/"); } builder.append('"'); String value = eTag.getValue(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '"') builder.append('\\'); builder.append(c); } builder.append('"'); return builder.toString(); }  EntityTag fromString(String eTag); String toString(EntityTag eTag);  }