model/src/test/java/eu/internetofus/common/model/ValidateContextTest.java
/**
   * Check that a range value is not valid.
   *
   * @param val         value that is not valid.
   * @param min         minimum range value.
   * @param max         maximum range value.
   * @param testContext test context to use.
   *
   * @see ValidateContext#validateNumberOnRangeField(String, Number, Number,
   *      Number, Promise)
   */
Check that a range value is not valid.
@param val         value that is not valid.
@param min         minimum range value.
@param max         maximum range value.
@param testContext test context to use.


Check that a range value is not valid . @param val value that is not valid . @param min minimum range value . @param max maximum range value . @param testContext test context to use .
@ParameterizedTest(name = "Should {0} not be on the range [{1},{2}]")
  @CsvSource({ "10,,1", "1,2,", "0.9999,1,3", "0,1,1", "-1,0,1", "2,0,1", "0,1,1.0000001" })
  public void shouldFailValidateNumberOnRangeField(final String val, final String min, final String max,
      final VertxTestContext testContext) {
    doReturn("codePrefixRange").when(this.context).errorCode();
    final Promise<Void> promise = Promise.promise();
    final Double value = Double.parseDouble(val);
    final var minValue = this.extractDouble(min);
    final var maxValue = this.extractDouble(max);
    this.context.validateNumberOnRangeField("range", value, minValue, maxValue, promise);
    testContext.assertFailure(promise.future()).onFailure(error -> {
      testContext.verify(() -> {
        assertThat(error).isInstanceOf(ValidationErrorException.class);
        final var cause = (ValidationErrorException) error;
        assertThat(cause.getCode()).isEqualTo("codePrefixRange.range");
        assertThat(cause.getMessage()).contains(String.valueOf(value));
      });
      testContext.completeNow();
    });
  }
@ ParameterizedTest ( name = "Should {0} not be on the range [{1},{2}]" ) @ CsvSource ( { "10,,1" , "1,2," , "0.9999,1,3" , "0,1,1" , "-1,0,1" , "2,0,1" , "0,1,1.0000001" } ) public void shouldFailValidateNumberOnRangeField ( final String val , final String min , final String max , final VertxTestContext testContext ) { doReturn ( "codePrefixRange" ) . when ( this . context ) . errorCode ( ) ; final Promise < Void > promise = Promise . promise ( ) ; final Double value = Double . parseDouble ( val ) ; final var minValue = this . extractDouble ( min ) ; final var maxValue = this . extractDouble ( max ) ; this . context . validateNumberOnRangeField ( "range" , value , minValue , maxValue , promise ) ; testContext . assertFailure ( promise . future ( ) ) . onFailure ( error -> { testContext . verify ( ( ) -> { assertThat ( error ) . isInstanceOf ( ValidationErrorException . class ) ; final var cause = ( ValidationErrorException ) error ; assertThat ( cause . getCode ( ) ) . isEqualTo ( "codePrefixRange.range" ) ; assertThat ( cause . getMessage ( ) ) . contains ( String . valueOf ( value ) ) ; } ) ; testContext . completeNow ( ) ; } ) ; }
Check that a range value is not valid.
Check that a range value is not valid .