Class AbstractSignalsTest

java.lang.Object
com.vaadin.tests.AbstractSignalsTest

public class AbstractSignalsTest extends Object
Base class for testing components with full-stack signals. Since signal bindings are only active when components are attached, this class sets up a mock UI instance for attaching components under test.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A bind method that takes a signal and a write callback, for example AppLayout::bindDrawerOpened.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected MockUIExtension
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected <C extends com.vaadin.flow.component.Component, T>
    Stream<org.junit.jupiter.api.DynamicTest>
    generateOneWayBindingTests(Supplier<C> componentFactory, BiConsumer<C,com.vaadin.flow.signals.local.ValueSignal<T>> bind, Function<C,T> getter, BiConsumer<C,T> setter, T initialValue, T updatedValue)
    Generates a suite of JUnit 5 dynamic tests that verify the standard behavior of a signal binding on a component property.
    protected <C extends com.vaadin.flow.component.Component, T>
    Stream<org.junit.jupiter.api.DynamicTest>
    generateTwoWayBindingTests(Supplier<C> componentFactory, AbstractSignalsTest.TwoWayBindMethod<C,T> bind, Function<C,T> getter, BiConsumer<C,T> setter, String propertyName, T initialValue, T updatedValue)
    Generates a suite of JUnit 5 dynamic tests that verify the standard behavior of a two-way signal binding on a component property, which is implemented with Element.bindProperty(String, Signal, SerializableConsumer).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • AbstractSignalsTest

      public AbstractSignalsTest()
  • Method Details

    • generateOneWayBindingTests

      protected <C extends com.vaadin.flow.component.Component, T> Stream<org.junit.jupiter.api.DynamicTest> generateOneWayBindingTests(Supplier<C> componentFactory, BiConsumer<C,com.vaadin.flow.signals.local.ValueSignal<T>> bind, Function<C,T> getter, BiConsumer<C,T> setter, T initialValue, T updatedValue)
      Generates a suite of JUnit 5 dynamic tests that verify the standard behavior of a signal binding on a component property. The returned stream is intended to be used with TestFactory.

      The suite contains the test cases of generateCommonBindingTests(Supplier, BiConsumer, Function, Object, Object). In addition, the following test case is generated:

      • manualSetWhileBoundThrows – verifies that imperative updates to a bound property via its setter throws a BindingActiveException.

      NOTE: The tests are not necessarily exhaustive for all aspects of a specific signal binding, but only cover common expected behaviors. Additional test cases may be needed for edge cases or specific implementation details of a particular binding.

      Type Parameters:
      C - the component type
      T - the property value type
      Parameters:
      componentFactory - supplier that creates a new component instance for each test
      bind - the bind method under test (e.g. DatePicker::bindMin)
      getter - the getter for the bound property (e.g. DatePicker::getMin)
      setter - the setter for the bound property (e.g. DatePicker::setMin), used to verify that imperative updates are rejected while a binding is active
      initialValue - the initial value of the signal created for each test
      updatedValue - a value different from initialValue, used to test synchronization behavior
      Returns:
      a stream of dynamic tests to be returned from a TestFactory method
    • generateTwoWayBindingTests

      protected <C extends com.vaadin.flow.component.Component, T> Stream<org.junit.jupiter.api.DynamicTest> generateTwoWayBindingTests(Supplier<C> componentFactory, AbstractSignalsTest.TwoWayBindMethod<C,T> bind, Function<C,T> getter, BiConsumer<C,T> setter, String propertyName, T initialValue, T updatedValue)
      Generates a suite of JUnit 5 dynamic tests that verify the standard behavior of a two-way signal binding on a component property, which is implemented with Element.bindProperty(String, Signal, SerializableConsumer). The returned stream is intended to be used with TestFactory.

      The suite contains the test cases of generateCommonBindingTests(Supplier, BiConsumer, Function, Object, Object), run with a write callback that sets the signal. In addition, the following test cases are generated:

      • bindNullWriteCallbackThrows – verifies that passing a null write callback to the bind method throws a NullPointerException.
      • setterWhileBoundCallsWriteCallback – verifies that calling the setter while bound invokes the write callback, which updates the signal and the component property.
      • setterWhileBoundRevertsWhenCallbackIgnoresValue – verifies that calling the setter while bound passes the value to the write callback, and that the component property reverts to the signal value when the callback does not update the signal.
      • clientUpdateCallsWriteCallback – verifies that a property change from the client invokes the write callback, which updates the signal and the component property.
      • signalChangeDoesNotCallWriteCallback – verifies that signal value changes update the component property without invoking the write callback.

      NOTE: The tests are not necessarily exhaustive for all aspects of a specific signal binding, but only cover common expected behaviors. Additional test cases may be needed for edge cases or specific implementation details of a particular binding.

      Type Parameters:
      C - the component type
      T - the property value type
      Parameters:
      componentFactory - supplier that creates a new component instance for each test
      bind - the bind method under test (e.g. AppLayout::bindDrawerOpened)
      getter - the getter for the bound property (e.g. AppLayout::isDrawerOpened)
      setter - the setter for the bound property (e.g. AppLayout::setDrawerOpened)
      propertyName - the name of the bound element property, used to simulate a property change from the client
      initialValue - the initial value of the signal created for each test
      updatedValue - a value different from initialValue, used to test synchronization behavior. Must be a type that the client can send as a property value.
      Returns:
      a stream of dynamic tests to be returned from a TestFactory method