コード例 #1
0
  @Test
  public void write_onPatchWithInnerObject_fullyWritesInnerObject() {
    TestData original = new TestData();
    TestData updated = new TestData();
    updated.setInnerData(new InnerTestData());

    Patch<TestData> patch =
        MakePatch.from(original).to(updated).with(new ReflectivePatchCalculator<>());
    JsonObject json = toJson(patch);

    assertTrue(json.has("innerData"));
    assertTrue(json.get("innerData").isJsonObject());

    JsonObject innerJson = json.get("innerData").getAsJsonObject();
    Collection<String[]> fields =
        Collections2.transform(
            innerJson.entrySet(),
            entry -> new String[] {entry.getKey(), entry.getValue().getAsString()});
    assertThat(
        fields,
        containsInAnyOrder(
            new String[] {"json-name-alias", "inner-named-value"},
            new String[] {"name1", "inner-value-1"},
            new String[] {"name2", "inner-value-2"}));
  }
コード例 #2
0
 @Theory
 public void testParseDate(TestData data) {
   try {
     assertThat(testee.parseDate(data.getFile()), is(equalTo(data.getExpectedDate())));
   } catch (Exception ex) {
     ex.printStackTrace(System.err);
     throw ex;
   }
 }
コード例 #3
0
  @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"));
  }
コード例 #4
0
  @Test
  public void write_onPatchWithNull_writesNullToJson() throws Exception {
    TestData original = new TestData();
    TestData updated = new TestData();
    updated.setName2(null);

    Patch<TestData> patch =
        MakePatch.from(original).to(updated).with(new ReflectivePatchCalculator<>());
    JsonObject json = toJson(patch);

    assertTrue(json.get("name2").isJsonNull());
    assertThat(json.has("nullName"), is(false));
  }
コード例 #5
0
  @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());
  }