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