HttpHeadersBase extends StringMultimap</* IN_NAME */ CharSequence, /* NAME */ AsciiString> implements HttpHeaderGetters { @Override public final int hashCode() { final int hashCode = super.hashCode(); return endOfStream ? ~hashCode : hashCode; } HttpHeadersBase(int sizeHint);   HttpHeadersBase(HttpHeadersBase parent, boolean shallowCopy);   HttpHeadersBase(HttpHeaderGetters parent); @Nullable @Override MediaType contentType(); @Override final boolean isEndOfStream(); @Override final int hashCode(); @Override boolean equals(@Nullable Object o); @Override final String toString();  }
@Test void headersWithSameNamesAndValuesShouldBeEquivalent() { final HttpHeadersBase headers1 = newEmptyHeaders(); headers1.add("name1", "value1"); headers1.add("name2", "value2"); headers1.add("name2", "value3"); final HttpHeadersBase headers2 = newEmptyHeaders(); headers2.add("name1", "value1"); headers2.add("name2", "value2"); headers2.add("name2", "value3"); assertThat(headers2).isEqualTo(headers1); assertThat(headers1).isEqualTo(headers2); assertThat(headers1).isEqualTo(headers1); assertThat(headers2).isEqualTo(headers2); assertThat(headers2.hashCode()).isEqualTo(headers1.hashCode()); assertThat(headers1.hashCode()).isEqualTo(headers1.hashCode()); assertThat(headers2.hashCode()).isEqualTo(headers2.hashCode()); }
@Test void emptyHeadersShouldBeEqual() { final HttpHeadersBase headers1 = newEmptyHeaders(); final HttpHeadersBase headers2 = newEmptyHeaders(); assertThat(headers2).isEqualTo(headers1); assertThat(headers2.hashCode()).isEqualTo(headers1.hashCode()); }
@Test void testEntryEquals() { final HttpHeadersBase nameValue = newEmptyHeaders(); nameValue.add("name", "value"); final HttpHeadersBase nameValueCopy = newEmptyHeaders(); nameValueCopy.add("name", "value"); final Map.Entry<AsciiString, String> same1 = nameValue.iterator().next(); final Map.Entry<AsciiString, String> same2 = nameValueCopy.iterator().next(); assertThat(same2).isEqualTo(same1); assertThat(same2.hashCode()).isEqualTo(same1.hashCode()); final HttpHeadersBase name1Value = newEmptyHeaders(); name1Value.add("name1", "value"); final HttpHeadersBase name2Value = newEmptyHeaders(); name2Value.add("name2", "value"); final Map.Entry<AsciiString, String> nameDifferent1 = name1Value.iterator().next(); final Map.Entry<AsciiString, String> nameDifferent2 = name2Value.iterator().next(); assertThat(nameDifferent1).isNotEqualTo(nameDifferent2); assertThat(nameDifferent1.hashCode()).isNotEqualTo(nameDifferent2.hashCode()); final HttpHeadersBase nameValue1 = newEmptyHeaders(); nameValue1.add("name", "value1"); final HttpHeadersBase nameValue2 = newEmptyHeaders(); nameValue2.add("name", "value2"); final Map.Entry<AsciiString, String> valueDifferent1 = nameValue1.iterator().next(); final Map.Entry<AsciiString, String> valueDifferent2 = nameValue2.iterator().next(); assertThat(valueDifferent1).isNotEqualTo(valueDifferent2); assertThat(valueDifferent1.hashCode()).isNotEqualTo(valueDifferent2.hashCode()); }