All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.remondis.remap.ReplaceCollectionAssertBuilder Maven / Gradle / Ivy

package com.remondis.remap;

import static com.remondis.remap.Lang.denyNull;

import java.util.Collection;
import java.util.function.Function;

/**
 * Builder to assert a replace operation on a {@link Mapper} object using {@link AssertMapping}.
 *
 * @param  The source type
 * @param  The destination type
 * @param  The type of the source field
 * @param  The type of the destination field
 * @author schuettec
 */
public class ReplaceCollectionAssertBuilder {

  private TypedPropertyDescriptor> sourceProperty;
  private TypedPropertyDescriptor> destProperty;
  private AssertMapping asserts;

  ReplaceCollectionAssertBuilder(TypedPropertyDescriptor> sourceProperty,
      TypedPropertyDescriptor> destProperty, AssertMapping asserts) {
    super();
    this.sourceProperty = sourceProperty;
    this.destProperty = destProperty;
    this.asserts = asserts;
  }

  /**
   * Specifies the transformation function that will be checked against null input.
   *
   * @param transformation The transformation to test.
   * @return Returns the {@link AssertMapping} for further configuration.
   */
  public AssertMapping andTest(Function transformation) {
    denyNull("tranfromation", transformation);
    ReplaceCollectionTransformation replace = new ReplaceCollectionTransformation<>(asserts.getMapping(),
        sourceProperty.property, destProperty.property, transformation, false);
    asserts.addAssertion(replace);
    return asserts;
  }

  /**
   * Specifies the transform operation to be skipped when null. In this case the transformation function will not be
   * tested. In a future release this method may allow to test the transformation function.
   *
   * @return Returns the {@link AssertMapping} for further configuration.
   */
  public AssertMapping andSkipWhenNull() {
    ReplaceCollectionTransformation replace = new ReplaceCollectionTransformation<>(asserts.getMapping(),
        sourceProperty.property, destProperty.property, null, true);
    asserts.addAssertion(replace);
    return asserts;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy