model/src/test/java/eu/internetofus/common/model/MergesTest.java
/**
   * Check can merge JSON objects.
   *
   * @see Merges#mergeJsonObjects(JsonObject, JsonObject)
   */
Check can merge JSON objects.
Check can merge JSON objects .
@Test
  public void shoulMergeJsonObjects() {
    assertThat(Merges.mergeJsonObjects(null, null)).isNull();
    final var source = new JsonObject();
    source.put("source", "source");
    source.put("key2", new JsonObject().put("subkey1", "value1").put("subkey2", true).put("subkey3", 1l));
    source.put("key3", 1l);
    source.put("key4", new JsonArray().add(1l).add("source").add(new JsonObject().put("key1", "value")));
    assertThat(Merges.mergeJsonObjects(null, source)).isSameAs(source);
    final var target = new JsonObject();
    target.put("target", "target");
    target.put("key2", new JsonObject().put("subkey1", true).put("subkey2", "value"));
    target.put("key3", true);
    target.put("key4", new JsonArray().add(5l).add(true).add(new JsonObject().put("key1", "value")));
    target.put("key5", "value5");
    assertThat(Merges.mergeJsonObjects(target, null)).isSameAs(target);
    final var merged = new JsonObject();
    merged.put("target", "target");
    merged.put("source", "source");
    merged.put("key2", new JsonObject().put("subkey1", "value1").put("subkey2", true).put("subkey3", 1l));
    merged.put("key3", 1l);
    merged.put("key4", new JsonArray().add(1l).add("source").add(new JsonObject().put("key1", "value")));
    merged.put("key5", "value5");
    assertThat(Merges.mergeJsonObjects(target, source)).isEqualTo(merged).isNotSameAs(target).isNotSameAs(source);
  }
@ Test public void shoulMergeJsonObjects ( ) { assertThat ( Merges . mergeJsonObjects ( null , null ) ) . isNull ( ) ; final var source = new JsonObject ( ) ; source . put ( "source" , "source" ) ; source . put ( "key2" , new JsonObject ( ) . put ( "subkey1" , "value1" ) . put ( "subkey2" , true ) . put ( "subkey3" , 1l ) ) ; source . put ( "key3" , 1l ) ; source . put ( "key4" , new JsonArray ( ) . add ( 1l ) . add ( "source" ) . add ( new JsonObject ( ) . put ( "key1" , "value" ) ) ) ; assertThat ( Merges . mergeJsonObjects ( null , source ) ) . isSameAs ( source ) ; final var target = new JsonObject ( ) ; target . put ( "target" , "target" ) ; target . put ( "key2" , new JsonObject ( ) . put ( "subkey1" , true ) . put ( "subkey2" , "value" ) ) ; target . put ( "key3" , true ) ; target . put ( "key4" , new JsonArray ( ) . add ( 5l ) . add ( true ) . add ( new JsonObject ( ) . put ( "key1" , "value" ) ) ) ; target . put ( "key5" , "value5" ) ; assertThat ( Merges . mergeJsonObjects ( target , null ) ) . isSameAs ( target ) ; final var merged = new JsonObject ( ) ; merged . put ( "target" , "target" ) ; merged . put ( "source" , "source" ) ; merged . put ( "key2" , new JsonObject ( ) . put ( "subkey1" , "value1" ) . put ( "subkey2" , true ) . put ( "subkey3" , 1l ) ) ; merged . put ( "key3" , 1l ) ; merged . put ( "key4" , new JsonArray ( ) . add ( 1l ) . add ( "source" ) . add ( new JsonObject ( ) . put ( "key1" , "value" ) ) ) ; merged . put ( "key5" , "value5" ) ; assertThat ( Merges . mergeJsonObjects ( target , source ) ) . isEqualTo ( merged ) . isNotSameAs ( target ) . isNotSameAs ( source ) ; }
Check can merge JSON objects.
Check can merge JSON objects .