@Test public void write_onAliasedFieldName_writesAliasToJson() throws Exception { TestData original = new TestData(); TestData updated = new TestData(); updated.setAliasedName("updated-aliased-value"); Patch<TestData> patch = MakePatch.from(original).to(updated).with(new ReflectivePatchCalculator<>()); JsonObject json = toJson(patch); assertThat(json.get("json-name-alias").getAsString(), is("updated-aliased-value")); }
@Test public void write_onPatchWithUnchangedFields_writesOnlyChangedFieldsToJson() throws Exception { TestData original = new TestData(); TestData updated = new TestData(); updated.setName1("updated value"); updated.setAliasedName(null); Patch<TestData> patch = MakePatch.from(original).to(updated).with(new ReflectivePatchCalculator<>()); JsonObject json = toJson(patch); assertThat(json.get("name1").getAsString(), is("updated value")); assertTrue(json.get("json-name-alias").isJsonNull()); }