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

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

There is a newer version: 4.3.7
Show newest version
package com.remondis.remap;

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

import java.util.function.Function;

import com.remondis.propertypath.api.PropertyPath;

/**
 * Builder to assert a replace operation on a {@link Mapper} object using {@link AssertConfiguration}.
 *
 * @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 ReplaceAssertBuilder {

  private TypedPropertyDescriptor sourceProperty;
  private TypedPropertyDescriptor destProperty;
  private AssertConfiguration asserts;

  ReplaceAssertBuilder(TypedPropertyDescriptor sourceProperty, TypedPropertyDescriptor destProperty,
      AssertConfiguration asserts) {
    super();
    this.sourceProperty = sourceProperty;
    this.destProperty = destProperty;
    this.asserts = asserts;
  }

  /**
   * Expects the mapping to evaluate the exact property path that was specified.
   *
   * @param propertyPath The expected property path.
   * @return Returns the {@link AssertConfiguration} for further configuration.
   */
  public  AssertConfiguration withPropertyPath(PropertyPath propertyPath) {
    denyNull("propertyPath", propertyPath);
    PropertyPathTransformation replace = new PropertyPathTransformation(asserts.getMapping(),
        sourceProperty.property, destProperty.property, propertyPath);
    asserts.addAssertion(replace);
    return asserts;
  }

  /**
   * Expects the mapping to evaluate the exact property path that was specified.
   *
   * @param propertyPath The expected property path.
   * @return Returns the {@link AssertConfiguration} for further configuration.
   */
  public AssertConfiguration withPropertyPathAndTransformation(PropertyPath propertyPath) {
    denyNull("propertyPath", propertyPath);
    PropertyPathTransformation replace = new PropertyPathTransformation<>(asserts.getMapping(),
        sourceProperty.property, destProperty.property, propertyPath, Function.identity());
    asserts.addAssertion(replace);
    return asserts;
  }

  /**
   * Expects the mapping to not skip the transform function on null input. The specified transform
   * function will be checked against null input.
   *
   * 

* Note: This method cannot reliably check that the specified function is actually the function that was configured on * the mapping. This method only verifies the skip-on-null behaviour and performs a null check on the * specified function. *

* * @param transformation The transformation to test. * @return Returns the {@link AssertConfiguration} for further configuration. */ public AssertConfiguration andTest(Function transformation) { denyNull("tranfromation", transformation); ReplaceTransformation replace = new ReplaceTransformation<>(asserts.getMapping(), sourceProperty.property, destProperty.property, transformation, false); asserts.addAssertion(replace); return asserts; } /** * Expects the mapping to skip the transform function on null input. * * @return Returns the {@link AssertConfiguration} for further configuration. */ public AssertConfiguration andSkipWhenNull() { ReplaceTransformation replace = new ReplaceTransformation(asserts.getMapping(), sourceProperty.property, destProperty.property, null, true); asserts.addAssertion(replace); return asserts; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy