### Question:
Entry { public static Entry create(String key, String value, EntryMetadata entryMetadata) { Utils.checkArgument(keyIsValid(key), "Invalid entry key name: %s", key); Utils.checkArgument(isValueValid(value), "Invalid entry value: %s", value); return new AutoValue_Entry(key, value, entryMetadata); } Entry(); static Entry create(String key, String value, EntryMetadata entryMetadata); abstract String getKey(); abstract String getValue(); abstract EntryMetadata getEntryMetadata(); static final int MAX_KEY_LENGTH; static final int MAX_VALUE_LENGTH; static final EntryMetadata METADATA_UNLIMITED_PROPAGATION; }### Answer:
@Test void testEntryEquals() { new EqualsTester() .addEqualityGroup( Entry.create(KEY, VALUE, METADATA_UNLIMITED_PROPAGATION), Entry.create(KEY, VALUE, METADATA_UNLIMITED_PROPAGATION)) .addEqualityGroup(Entry.create(KEY, VALUE_2, METADATA_UNLIMITED_PROPAGATION)) .addEqualityGroup(Entry.create(KEY_2, VALUE, METADATA_UNLIMITED_PROPAGATION)) .addEqualityGroup(Entry.create(KEY, VALUE, METADATA_NO_PROPAGATION)) .testEquals(); }
@Test void create_AllowEntryKeyNameWithMaxLength() { char[] chars = new char[Entry.MAX_KEY_LENGTH]; Arrays.fill(chars, 'k'); String key = new String(chars); assertThat(Entry.create(key, "value", Entry.METADATA_UNLIMITED_PROPAGATION)).isNotNull(); }
@Test void create_DisallowEntryKeyNameOverMaxLength() { char[] chars = new char[Entry.MAX_KEY_LENGTH + 1]; Arrays.fill(chars, 'k'); String key = new String(chars); assertThrows( IllegalArgumentException.class, () -> Entry.create(key, "value", Entry.METADATA_UNLIMITED_PROPAGATION)); }
@Test void create_DisallowKeyUnprintableChars() { assertThrows( IllegalArgumentException.class, () -> Entry.create("\2ab\3cd", "value", Entry.METADATA_UNLIMITED_PROPAGATION)); }
@Test void createString_DisallowKeyEmpty() { assertThrows( IllegalArgumentException.class, () -> Entry.create("", "value", Entry.METADATA_UNLIMITED_PROPAGATION)); }
@Test void create_DisallowEntryValueOverMaxLength() { char[] chars = new char[Entry.MAX_VALUE_LENGTH + 1]; Arrays.fill(chars, 'v'); String value = new String(chars); assertThrows( IllegalArgumentException.class, () -> Entry.create("key", value, Entry.METADATA_UNLIMITED_PROPAGATION)); }
@Test void disallowEntryValueWithUnprintableChars() { String value = "\2ab\3cd"; assertThrows( IllegalArgumentException.class, () -> Entry.create("key", value, Entry.METADATA_UNLIMITED_PROPAGATION)); }