Package com.vaadin.tests
Class AbstractSignalsTest
java.lang.Object
com.vaadin.tests.AbstractSignalsTest
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <C extends com.vaadin.flow.component.Component,T>
Stream<org.junit.jupiter.api.DynamicTest> generateBindingTests(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.
-
Field Details
-
ui
-
-
Constructor Details
-
AbstractSignalsTest
public AbstractSignalsTest()
-
-
Method Details
-
generateBindingTests
protected <C extends com.vaadin.flow.component.Component,T> Stream<org.junit.jupiter.api.DynamicTest> generateBindingTests(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 withTestFactory.The following test cases are generated:
- synchronizesWhileAttached – verifies that the component property reflects the signal's initial value after binding and updates when the signal value changes, while the component is attached to a UI.
- appliesInitialValueWhileDetached – verifies that the signal's initial value is applied to the component property immediately upon binding, even when the component is not attached to a UI.
- doesNotSynchronizeWhileDetached – verifies that subsequent signal value changes are not propagated to the component property while the component is detached.
- resynchronizesAfterAttach – verifies that the component property catches up with the latest signal value when the component is attached to a UI after the signal was updated while detached.
- manualSetWhileBoundThrows – verifies that imperative updates
to a bound property via its setter throws a
BindingActiveException. - rebindWhileBoundThrows – verifies that calling the bind method
again while a binding is already active throws a
BindingActiveException. - bindNullSignalThrows – verifies that passing a
nullsignal to the bind method throws aNullPointerException.
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 typeT- the property value type- Parameters:
componentFactory- supplier that creates a new component instance for each testbind- 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 activeinitialValue- the initial value of the signal created for each testupdatedValue- a value different frominitialValue, used to test synchronization behavior- Returns:
- a stream of dynamic tests to be returned from a
TestFactorymethod
-