Headers { public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); } private  Headers(Builder builder); private  Headers(String[] namesAndValues); String get(String name); Date getDate(String name); int size(); String name(int index); String value(int index); Set<String> names(); List<String> values(String name); Builder newBuilder(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Map<String, List<String>> toMultimap(); Map<String, String> toMap(); static Headers of(String... namesAndValues); static Headers of(Map<String, String> headers); static Headers ofMMap(Map<String, List<String>> headers);  }
@Test public void ofThrowsOddNumberOfHeaders() { try { Headers.of("User-Agent", "OkHttp", "Content-Length"); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofThrowsOnNull() { try { Headers.of("User-Agent", null); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofThrowsOnEmptyName() { try { Headers.of("", "OkHttp"); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofRejectsNulChar() { try { Headers.of("User-Agent", "Square\u0000OkHttp"); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofMapThrowsOnNull() { try { Headers.of(Collections.<String, String>singletonMap("User-Agent", null)); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofMapThrowsOnEmptyName() { try { Headers.of(Collections.singletonMap("", "OkHttp")); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofMapThrowsOnBlankName() { try { Headers.of(Collections.singletonMap(" ", "OkHttp")); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofMapRejectsNulCharInName() { try { Headers.of(Collections.singletonMap("User-Agent", "Square\u0000OkHttp")); fail(); } catch (IllegalArgumentException expected) { } }
@Test public void ofMapRejectsNulCharInValue() { try { Headers.of(Collections.singletonMap("User-\u0000Agent", "OkHttp")); fail(); } catch (IllegalArgumentException expected) { } }