Change implements Serializable { public static <C extends Identified<?>> Change<C> delete(C oldObject) { Preconditions.checkArgument(oldObject != null, "Attempted to create a deletion of a null oldObject"); return new Change<>(oldObject, null); } private  Change(@Nullable C originalObject, @Nullable C newObject); static Change<C> add(C newObject); static Change<C> update(C oldObject, C newObject); static Change<C> delete(C oldObject); static Change<C> identity(C object); Change<C> map(UnaryOperator<C> mapper); Optional<C> getNewObject(); Optional<C> getOriginalObject(); Identity<?> getId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @CheckForNull final C originalObject; @CheckForNull final C newObject; }
@Test void delete_withNonNull_returnsExpected() { Change<TestState> delete = Change.delete(OBJECT1_V1); Assertions.assertEquals(OBJECT1_V1, delete.originalObject, "Original object not set as expected"); Assertions.assertNull(delete.newObject, "New object set unexpectedly"); }
@Test void delete_withNull_throwsException() { Assertions.assertThrows(IllegalArgumentException.class, () -> Change.delete(null), "Expected exception on deleting a null state"); }