Change implements Serializable { public static <C extends Identified<?>> Change<C> add(C newObject) { Preconditions.checkArgument(newObject != null, "Attempted to create an addition of a null newObject"); return new Change<>(null, newObject); } 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 add_withNonNull_returnsExpected() { Change<TestState> add = Change.add(OBJECT1_V1); Assertions.assertNull(add.originalObject, "Original object set unexpectedly"); Assertions.assertEquals(OBJECT1_V1, add.newObject, "New object not set as expected"); }
@Test void add_withNull_throwsException() { Assertions.assertThrows(IllegalArgumentException.class, () -> Change.add(null), "Expected exception on adding a null state"); }