Class LitRendererTestUtil

java.lang.Object
com.vaadin.testbench.unit.LitRendererTestUtil

public class LitRendererTestUtil extends Object
Utility methods for unit testing properties and functions of LitRenderers.
  • Method Details

    • getProperties

      public static <Y> Set<String> getProperties(LitRenderer<Y> litRenderer, BiFunction<Class<?>,String,Field> fieldGetter)
      Gets the property names for the supplied LitRenderer using the given field getter.
      Type Parameters:
      Y - the type being renderer by the LitRenderer
      Parameters:
      litRenderer - the LitRenderer with properties to get
      fieldGetter - the field getter of the ComponentTester
      Returns:
      the set of property names of the LitRenderer
    • getPropertyValue

      public static <Y, V> V getPropertyValue(LitRenderer<Y> litRenderer, BiFunction<Class<?>,String,Field> fieldGetter, IntFunction<Y> itemGetter, int index, String propertyName, Class<V> propertyClass)
      Gets the property value for the supplied LitRenderer.
      Type Parameters:
      Y - the type being renderer by the LitRenderer
      V - the type of the property value
      Parameters:
      litRenderer - the LitRenderer with properties to get
      fieldGetter - the field getter of the ComponentTester
      itemGetter - the getter for the item rendered by the LitRenderer
      index - the index of the item rendered by the LitRenderer
      propertyName - the name of the property of the LitRenderer
      propertyClass - the type of the property value
      Returns:
      the property value
      Throws:
      IllegalArgumentException - when the type of property value does not match propertyClass
    • getFunctionNames

      public static <Y> Set<String> getFunctionNames(LitRenderer<Y> litRenderer, BiFunction<Class<?>,String,Field> fieldGetter)
      Gets the function names for the supplied LitRenderer using the given field getter.
      Type Parameters:
      Y - the type being renderer by the LitRenderer
      Parameters:
      litRenderer - the LitRenderer with properties to get
      fieldGetter - the field getter of the ComponentTester
      Returns:
      the set of function names of the LitRenderer
    • invokeFunction

      public static <Y> void invokeFunction(LitRenderer<Y> litRenderer, BiFunction<Class<?>,String,Field> fieldGetter, IntFunction<Y> itemGetter, int index, String functionName, elemental.json.JsonArray jsonArray)
      Invokes the function by name for the supplied LitRenderer using the given field getter.
      Type Parameters:
      Y - the type being renderer by the LitRenderer
      Parameters:
      litRenderer - the LitRenderer with properties to get
      fieldGetter - the field getter of the ComponentTester
      itemGetter - the getter for the item rendered by the LitRenderer
      index - the index of the item rendered by the LitRenderer
      functionName - the name of the function of the LitRenderer
      jsonArray - additional parameters to pass to the function
      Throws:
      IllegalArgumentException - when the function is not registered in LitRenderer