Package com.vaadin.tests
Class MockUIRule
java.lang.Object
org.junit.rules.ExternalResource
com.vaadin.tests.MockUIRule
- All Implemented Interfaces:
org.junit.rules.TestRule
public class MockUIRule
extends org.junit.rules.ExternalResource
JUnit rule to set up a UI and VaadinSession for testing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(com.vaadin.flow.component.Component component) Add a component to the UI.protected voidafter()protected voidbefore()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 rule.com.vaadin.flow.server.VaadinSessionGet the VaadinSession instance that is set up by this rule.com.vaadin.flow.component.UIgetUI()Get the UI instance that is set up by this rule.voidremove(com.vaadin.flow.component.Component component) Remove a component from the UI.voidSet the locale of the UI.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
MockUIRule
public MockUIRule()
-
-
Method Details
-
before
protected void before()- Overrides:
beforein classorg.junit.rules.ExternalResource
-
after
protected void after()- Overrides:
afterin classorg.junit.rules.ExternalResource
-
getUI
public com.vaadin.flow.component.UI getUI()Get the UI instance that is set up by this rule.- Returns:
- the UI instance
-
getSession
public com.vaadin.flow.server.VaadinSession getSession()Get the VaadinSession instance that is set up by this rule.- Returns:
- the VaadinSession instance
-
getService
public com.vaadin.flow.server.VaadinService getService()Get the VaadinService instance that is set up by this rule.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 toHasComponents.remove(Component...)for convenience.- Parameters:
component- the component to remove
-
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
-