model/src/test/java/eu/internetofus/common/model/ValidateContextTest.java
/**
   * Should fail validate list field because duplicated field.
   *
   * @param testContext test context to use.
   * @param element1    to validate.
   * @param element2    to validate.
   * @param element3    to validate.
   * @param context1    to validate.
   * @param context2    to validate.
   * @param context3    to validate.
   *
   * @see ValidateContext#validateListField(String, java.util.List,
   *      java.util.function.BiPredicate)
   */
Should fail validate list field because duplicated field.
@param testContext test context to use.
@param element1    to validate.
@param element2    to validate.
@param element3    to validate.
@param context1    to validate.
@param context2    to validate.
@param context3    to validate.


Should fail validate list field because duplicated field . @param testContext test context to use . @param element1 to validate . @param element2 to validate . @param element3 to validate . @param context1 to validate . @param context2 to validate . @param context3 to validate .
@SuppressWarnings({ "rawtypes", "unchecked" })
  @Test
  public void shouldFailValidateListFieldBecauseDuplicated(final VertxTestContext testContext,
      @Mock final Validable element1, @Mock final Validable element2, @Mock final Validable element3,
      @Mock(answer = Answers.CALLS_REAL_METHODS) final ValidateContext<?> context1,
      @Mock(answer = Answers.CALLS_REAL_METHODS) final ValidateContext<?> context2,
      @Mock(answer = Answers.CALLS_REAL_METHODS) final ValidateContext<?> context3) {
    doReturn("model").when(this.context).errorCode();
    doReturn(context1).when(this.context).createContextWithErrorCode("model.list[0]");
    doReturn(context2).when(this.context).createContextWithErrorCode("model.list[1]");
    doReturn(context3).when(this.context).createContextWithErrorCode("model.list[2]");
    doReturn("model.list[2]").when(context3).errorCode();
    final List<Validable> model = new ArrayList<>();
    model.add(element1);
    model.add(element2);
    model.add(element3);
    doReturn(Future.succeededFuture()).when(element1).validate(context1);
    doReturn(Future.succeededFuture()).when(element2).validate(context2);
    final Future<Void> future = Future.succeededFuture()
        .compose(this.context.validateListField("list", model, (a, b) -> a == element3));
    testContext.assertFailure(future).onFailure(error -> {
      testContext.verify(() -> {
        assertThat(error).isInstanceOf(ValidationErrorException.class);
        final var cause = (ValidationErrorException) error;
        assertThat(cause.getCode()).isEqualTo("model.list[2]");
        assertThat(cause.getMessage()).contains("0");
      });
      testContext.completeNow();
    });
  }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) @ Test public void shouldFailValidateListFieldBecauseDuplicated ( final VertxTestContext testContext , @ Mock final Validable element1 , @ Mock final Validable element2 , @ Mock final Validable element3 , @ Mock ( answer = Answers . CALLS_REAL_METHODS ) final ValidateContext < ? > context1 , @ Mock ( answer = Answers . CALLS_REAL_METHODS ) final ValidateContext < ? > context2 , @ Mock ( answer = Answers . CALLS_REAL_METHODS ) final ValidateContext < ? > context3 ) { doReturn ( "model" ) . when ( this . context ) . errorCode ( ) ; doReturn ( context1 ) . when ( this . context ) . createContextWithErrorCode ( "model.list[0]" ) ; doReturn ( context2 ) . when ( this . context ) . createContextWithErrorCode ( "model.list[1]" ) ; doReturn ( context3 ) . when ( this . context ) . createContextWithErrorCode ( "model.list[2]" ) ; doReturn ( "model.list[2]" ) . when ( context3 ) . errorCode ( ) ; final List < Validable > model = new ArrayList < > ( ) ; model . add ( element1 ) ; model . add ( element2 ) ; model . add ( element3 ) ; doReturn ( Future . succeededFuture ( ) ) . when ( element1 ) . validate ( context1 ) ; doReturn ( Future . succeededFuture ( ) ) . when ( element2 ) . validate ( context2 ) ; final Future < Void > future = Future . succeededFuture ( ) . compose ( this . context . validateListField ( "list" , model , ( a , b ) -> a == element3 ) ) ; testContext . assertFailure ( future ) . onFailure ( error -> { testContext . verify ( ( ) -> { assertThat ( error ) . isInstanceOf ( ValidationErrorException . class ) ; final var cause = ( ValidationErrorException ) error ; assertThat ( cause . getCode ( ) ) . isEqualTo ( "model.list[2]" ) ; assertThat ( cause . getMessage ( ) ) . contains ( "0" ) ; } ) ; testContext . completeNow ( ) ; } ) ; }
Should fail validate list field because duplicated field.
Should fail validate list field because duplicated field .