Package com.vaadin.tests
Class MockUIExtension
java.lang.Object
com.vaadin.tests.MockUIExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension
public class MockUIExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
JUnit extension to set up a UI and VaadinSession for testing.
Usage:
@RegisterExtension MockUIExtension ui = new MockUIExtension();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(com.vaadin.flow.component.Component component) Add a component to the UI.voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) voidclearUI()Clears the current the UI.List<com.vaadin.flow.component.internal.PendingJavaScriptInvocation> Dump the pending JavaScript invocations from the UI internals.voidSimulate client communication by running pending executions and collecting changes.com.vaadin.flow.server.VaadinServiceGet the VaadinService instance that is set up by this extension.com.vaadin.flow.server.VaadinSessionGet the VaadinSession instance that is set up by this extension.com.vaadin.flow.component.UIgetUI()Get the UI instance that is set up by this extension.voidremove(com.vaadin.flow.component.Component component) Remove a component from the UI.voidRemove all components from the UI.voidReplaces the current UI with a new instance.voidSet the locale of the UI.
-
Constructor Details
-
MockUIExtension
public MockUIExtension()
-
-
Method Details
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback
-
getUI
public com.vaadin.flow.component.UI getUI()Get the UI instance that is set up by this extension.- Returns:
- the UI instance
-
clearUI
public void clearUI()Clears the current the UI. -
replaceUI
public void replaceUI()Replaces the current UI with a new instance. -
getSession
public com.vaadin.flow.server.VaadinSession getSession()Get the VaadinSession instance that is set up by this extension.Note that this returns a Mockito spy, so it supports stubbing and verification.
- Returns:
- the VaadinSession instance
-
getService
public com.vaadin.flow.server.VaadinService getService()Get the VaadinService instance that is set up by this extension.Note that this returns a Mockito mock, so it supports stubbing and verification.
- Returns:
- the VaadinService instance
-
add
public void add(com.vaadin.flow.component.Component component) Add a component to the UI. Delegates toUI.add(Component...)for convenience.- Parameters:
component- the component to add
-
remove
public void remove(com.vaadin.flow.component.Component component) Remove a component from the UI. Delegates toHasComponentsOfType.remove(Component...)for convenience.- Parameters:
component- the component to remove
-
removeAll
public void removeAll()Remove all components from the UI. Delegates toHasComponentsOfType.removeAll()for convenience. -
setLocale
Set the locale of the UI. Delegates toUI.setLocale(Locale)for convenience.- Parameters:
locale- the locale to set
-
fakeClientCommunication
public void fakeClientCommunication()Simulate client communication by running pending executions and collecting changes. -
dumpPendingJavaScriptInvocations
public List<com.vaadin.flow.component.internal.PendingJavaScriptInvocation> dumpPendingJavaScriptInvocations()Dump the pending JavaScript invocations from the UI internals.- Returns:
- a list of pending JavaScript invocations
-