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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(com.vaadin.flow.component.Component component)
    Add a component to the UI.
    protected void
     
    protected void
     
    List<com.vaadin.flow.component.internal.PendingJavaScriptInvocation>
    Dump the pending JavaScript invocations from the UI internals.
    void
    Simulate client communication by running pending executions and collecting changes.
    com.vaadin.flow.server.VaadinService
    Get the VaadinService instance that is set up by this rule.
    com.vaadin.flow.server.VaadinSession
    Get the VaadinSession instance that is set up by this rule.
    com.vaadin.flow.component.UI
    Get the UI instance that is set up by this rule.
    void
    remove(com.vaadin.flow.component.Component component)
    Remove a component from the UI.
    void
    setLocale(Locale locale)
    Set the locale of the UI.

    Methods inherited from class org.junit.rules.ExternalResource

    apply

    Methods inherited from class java.lang.Object

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

    • MockUIRule

      public MockUIRule()
  • Method Details

    • before

      protected void before()
      Overrides:
      before in class org.junit.rules.ExternalResource
    • after

      protected void after()
      Overrides:
      after in class org.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 to UI.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 to HasComponents.remove(Component...) for convenience.
      Parameters:
      component - the component to remove
    • setLocale

      public void setLocale(Locale locale)
      Set the locale of the UI. Delegates to UI.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