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