vertx/src/test/java/eu/internetofus/common/vertx/RepositoryTest.java
/**
   * Verify that obtain the sort object form a set of values.
   *
   * @param param with the values to convert.
   *
   * @see Repository#queryParamToSort(Iterable, String,Function)
   */
Verify that obtain the sort object form a set of values.
@param param with the values to convert.


Verify that obtain the sort object form a set of values . @param param with the values to convert .
@ParameterizedTest(name = "Should sort {0}")
  @ValueSource(strings = { "key;{\"KEY\":1}", "+KeY;{\"KEY\":1}", " -key ;{\"KEY\":-1}",
      "key1 , key2 , key3;{\"KEY1\":1,\"KEY2\":1,\"KEY3\":1}",
      " key1 , +key2 , -key3 ;{\"KEY1\":1,\"KEY2\":1,\"KEY3\":-1}" })
  public void shouldSort(final String param) {
    assertThatCode(() -> {
      final var endIndex = param.indexOf(';');
      final var values = param.substring(0, endIndex).split(",");
      final var expected = param.substring(endIndex + 1).trim();
      final var sortExpected = (JsonObject) Json.decodeValue(expected);
      assertThat(Repository.queryParamToSort(Arrays.asList(values), "codePrefix", (value) -> {
        final var key = value.toUpperCase();
        if (!key.startsWith("KEY")) {
          return null;
        } else {
          return key;
        }
      })).isEqualTo(sortExpected);
    }).doesNotThrowAnyException();
  }
@ ParameterizedTest ( name = "Should sort {0}" ) @ ValueSource ( strings = { "key;{\"KEY\":1}" , "+KeY;{\"KEY\":1}" , " -key ;{\"KEY\":-1}" , "key1 , key2 , key3;{\"KEY1\":1,\"KEY2\":1,\"KEY3\":1}" , " key1 , +key2 , -key3 ;{\"KEY1\":1,\"KEY2\":1,\"KEY3\":-1}" } ) public void shouldSort ( final String param ) { assertThatCode ( ( ) -> { final var endIndex = param . indexOf ( ';' ) ; final var values = param . substring ( 0 , endIndex ) . split ( "," ) ; final var expected = param . substring ( endIndex + 1 ) . trim ( ) ; final var sortExpected = ( JsonObject ) Json . decodeValue ( expected ) ; assertThat ( Repository . queryParamToSort ( Arrays . asList ( values ) , "codePrefix" , ( value ) -> { final var key = value . toUpperCase ( ) ; if ( ! key . startsWith ( "KEY" ) ) { return null ; } else { return key ; } } ) ) . isEqualTo ( sortExpected ) ; } ) . doesNotThrowAnyException ( ) ; }
Verify that obtain the sort object form a set of values.
Verify that obtain the sort object form a set of values .