Class Locator

java.lang.Object
com.vaadin.browserless.internal.Locator

public final class Locator extends Object
Functions for looking up components in the component tree.

For internal use only. May be renamed or removed in a future release.

  • Method Details

    • filterNotBlank

      public static List<String> filterNotBlank(Iterable<String> strings)
      Returns the non-null, non-blank strings of given iterable.
      Parameters:
      strings - the strings to filter, not null.
      Returns:
      the non-null, non-blank strings.
    • _get

      public static <T extends Component> T _get(Component receiver, Class<T> clazz, Consumer<SearchSpec<T>> block)
      Finds a VISIBLE component of given clazz which matches given block. This component and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      receiver - the component to search in.
      clazz - the component must be of this class.
      block - the search specification
      Returns:
      the only matching component, never null.
      Throws:
      AssertionError - if no component matched, or if more than one component matches.
    • _get

      public static <T extends Component> T _get(Class<T> clazz, Consumer<SearchSpec<T>> block)
      Finds a VISIBLE component in the current UI of given clazz which matches given block. The current UI and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      clazz - the component must be of this class.
      block - the search specification
      Returns:
      the only matching component, never null.
      Throws:
      AssertionError - if no component matched, or if more than one component matches.
    • _find

      public static <T extends Component> List<T> _find(Component receiver, Class<T> clazz, Consumer<SearchSpec<T>> block)
      Finds a list of VISIBLE components of given clazz which matches block. This component and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      receiver - the component to search in.
      clazz - the component must be of this class.
      block - the search specification
      Returns:
      the list of matching components, may be empty.
      Throws:
      AssertionError - if the number of matching components is not within the expected count.
    • _find

      public static <T extends Component> List<T> _find(Class<T> clazz, Consumer<SearchSpec<T>> block)
      Finds a list of VISIBLE components of given clazz which matches block. The UI.getCurrent() and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      clazz - the component must be of this class.
      block - the search specification
      Returns:
      the list of matching components, may be empty.
    • _walkAll

      public static Iterable<Component> _walkAll(Component receiver)
      Walks the component child/descendant tree, depth-first: first the component, then its descendants, then its next sibling.
      Parameters:
      receiver - the root component.
      Returns:
      the iterable over the component and all of its descendants.
    • _expectNone

      public static <T extends Component> void _expectNone(Component receiver, Class<T> clazz, Consumer<SearchSpec<T>> block)
      Expects that there are no VISIBLE components of given clazz which matches block. This component and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      receiver - the component to search in.
      clazz - the component class.
      block - the search specification
      Throws:
      AssertionError - if one or more components matched.
    • _expectNoDialogs

      public static void _expectNoDialogs()
      Expects that there are no dialogs shown. The dialog types come from the registered ComponentSupport implementations.
      Throws:
      AssertionError - if a dialog is shown.
      IllegalStateException - if no ComponentSupport reports any dialog type.
    • _expectNone

      public static <T extends Component> void _expectNone(Class<T> clazz, Consumer<SearchSpec<T>> block)
      Expects that there are no VISIBLE components in the current UI of given clazz which matches block. The current UI and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      clazz - the component class.
      block - the search specification
      Throws:
      AssertionError - if one or more components matched.
    • _expectOne

      public static <T extends Component> void _expectOne(Component receiver, Class<T> clazz, Consumer<SearchSpec<T>> block)
      Expects that there is exactly one VISIBLE components of given clazz which matches block. This component and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      receiver - the component to search in.
      clazz - the component class.
      block - the search specification
      Throws:
      AssertionError - if none, or more than one components matched.
    • _expectOne

      public static <T extends Component> void _expectOne(Class<T> clazz, Consumer<SearchSpec<T>> block)
      Expects that there is exactly one VISIBLE components in the current UI of given clazz which matches block. The current UI and all of its descendants are searched.
      Type Parameters:
      T - the component type
      Parameters:
      clazz - the component class.
      block - the search specification
      Throws:
      AssertionError - if none, or more than one components matched.
    • _expect

      public static <T extends Component> void _expect(Component receiver, Class<T> clazz, int count, Consumer<SearchSpec<T>> block)
      Expects that there are exactly count VISIBLE components of given clazz match block. This component and all of its descendants are searched.

      Special cases: for asserting one component use _expectOne. For asserting no components use _expectNone.

      Type Parameters:
      T - the component type
      Parameters:
      receiver - the component to search in.
      clazz - the component class.
      count - the expected number of matching components.
      block - the search specification
      Throws:
      AssertionError - if incorrect count of component matched.
    • _expect

      public static <T extends Component> void _expect(Class<T> clazz, int count, Consumer<SearchSpec<T>> block)
      Expects that there are exactly count VISIBLE components in the current UI with given clazz match block. The current UI and all of its descendants are searched.

      Special cases: for asserting one component use _expectOne. For asserting no components use _expectNone. They provide a better error message in case of a failure, and also communicate your intent as a test writer better in the test code.

      Type Parameters:
      T - the component type
      Parameters:
      clazz - the component class.
      count - the expected number of matching components.
      block - the search specification
      Throws:
      AssertionError - if incorrect count of component matched.
    • _expectInternalServerError

      public static void _expectInternalServerError(String expectedErrorMessage)
      Asserts that the InternalServerError page is currently being shown, optionally with given expectedErrorMessage.
      Parameters:
      expectedErrorMessage - the text the error message must contain; an empty string matches any message.
    • getCurrentPath

      public static String getCurrentPath()
      Returns the browser's current path. Returns null if there is no current UI.
      Returns:
      the current path with query parameters, or null.