All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mvysny.kaributesting.v8.LocatorJ Maven / Gradle / Ivy

package com.github.mvysny.kaributesting.v8;

import com.vaadin.data.HasValue;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;

import com.vaadin.ui.UI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Consumer;

import kotlin.Unit;

/**
 * To use this class, don't forget to add import static com.github.karibu.testing.LocatorJ.*; to your test class.
 *
 * @author mavi
 */
public class LocatorJ {
    /**
     * Finds a VISIBLE component of given type which matches given class. {@link UI#getCurrent()} and all of its descendants are searched.
     *
     * @param clazz the component class
     * @return the only matching component, never null.
     * @throws AssertionError if no component matched, or if more than one component matches.
     */
    @NotNull
    public static  T _get(@NotNull Class clazz) {
        return LocatorKt._get(clazz, searchSpec -> Unit.INSTANCE);
    }

    /**
     * Finds a VISIBLE component in the current UI of given clazz which matches given spec. The {@link UI#getCurrent()} and all of its descendants are searched.
     * 

* Example: * import static com.github.karibu.testing.LocatorJ.*; _get(TextField.class, spec -> spec.withCaption("Name:").withId("name")); * * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @return the only matching component, never null. * @throws AssertionError if no component matched, or if more than one component matches. */ @NotNull public static T _get(@NotNull Class clazz, @NotNull Consumer> spec) { return LocatorKt._get(clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Finds a VISIBLE component of given type which matches given class. The receiver and all of its descendants are searched. * * @param receiver the parent layout to search in, not null. * @param clazz the component class * @return the only matching component, never null. * @throws AssertionError if no component matched, or if more than one component matches. */ @NotNull public static T _get(@NotNull Component receiver, @NotNull Class clazz) { return LocatorKt._get(receiver, clazz, searchSpec -> Unit.INSTANCE); } /** * Finds a VISIBLE component in the current UI of given clazz which matches given spec. The receiver and all of its descendants are searched. *

* Example: * import static com.github.karibu.testing.LocatorJ.*; _get(layout, TextField.class, spec -> spec.withCaption("Name:").withId("name")); * * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @return the only matching component, never null. * @throws AssertionError if no component matched, or if more than one component matches. */ @NotNull public static T _get(@NotNull Component receiver, @NotNull Class clazz, @NotNull Consumer> spec) { return LocatorKt._get(receiver, clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Clicks the button, but only if it is actually possible to do so by the user. If the button is read-only or disabled, an exception is thrown. * * @throws IllegalStateException if the button was not visible or not enabled. */ public static void _click(@NotNull Button receiver) { ButtonKt._click(receiver); } /** * Sets the value of given component, but only if it is actually possible to do so by the user. * If the component is read-only or disabled, an exception is thrown. * * @throws IllegalStateException if the field was not visible, not enabled or was read-only. */ public static void _setValue(@NotNull HasValue receiver, @Nullable V value) { BasicUtilsKt.set_value(receiver, value); } /** * Finds a list of VISIBLE components of given class. {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @return the list of matching components, may be empty. */ public static List _find(@NotNull Class clazz) { return LocatorKt._find(clazz, spec -> Unit.INSTANCE); } /** * Finds a list of VISIBLE components of given class. {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @return the list of matching components, may be empty. */ public static List _find(@NotNull Class clazz, @NotNull Consumer> spec) { return LocatorKt._find(clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Finds a list of VISIBLE components of given [clazz]. The [receiver] and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @return the list of matching components, may be empty. */ public static List _find(@NotNull Component receiver, @NotNull Class clazz) { return LocatorKt._find(receiver, clazz, spec -> Unit.INSTANCE); } /** * Finds a list of VISIBLE components of given [clazz] which matches spec. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @return the list of matching components, may be empty. */ public static List _find(@NotNull Component receiver, @NotNull Class clazz, @NotNull Consumer> spec) { return LocatorKt._find(receiver, clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there are no VISIBLE components in the current UI of given class. The {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @throws AssertionError if one or more components matched. */ public static void _assertNone(@NotNull Class clazz) { LocatorKt._expectNone(clazz, spec -> Unit.INSTANCE); } /** * Expects that there are no VISIBLE components in the current UI of given class which matches spec. The {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @throws AssertionError if one or more components matched. */ public static void _assertNone(@NotNull Class clazz, @NotNull Consumer> spec) { LocatorKt._expectNone(clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there are no VISIBLE components of given class. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @throws AssertionError if one or more components matched. */ public static void _assertNone(@NotNull Component receiver, @NotNull Class clazz) { LocatorKt._expectNone(receiver, clazz, ss -> Unit.INSTANCE); } /** * Expects that there are no VISIBLE components of given class matching given spec. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @throws AssertionError if one or more components matched. */ public static void _assertNone(@NotNull Component receiver, @NotNull Class clazz, @NotNull Consumer> spec) { LocatorKt._expectNone(receiver, clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there is exactly ono VISIBLE components in the current UI of given class. The {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @throws AssertionError if none, or more than one components matched. */ public static void _assertOne(@NotNull Class clazz) { LocatorKt._expectOne(clazz, spec -> Unit.INSTANCE); } /** * Expects that there is exactly one VISIBLE components in the current UI of given class which matches spec. The {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @throws AssertionError if none, or more than one components matched. */ public static void _assertOne(@NotNull Class clazz, @NotNull Consumer> spec) { LocatorKt._expectOne(clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there is exactly one VISIBLE components of given class. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @throws AssertionError if none, or more than one components matched. */ public static void _assertOne(@NotNull Component receiver, @NotNull Class clazz) { LocatorKt._expectOne(receiver, clazz, ss -> Unit.INSTANCE); } /** * Expects that there is exactly one VISIBLE components of given class matching given spec. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param spec allows you to add search criterion. * @throws AssertionError if none, or more than one components matched. */ public static void _assertOne(@NotNull Component receiver, @NotNull Class clazz, @NotNull Consumer> spec) { LocatorKt._expectOne(receiver, clazz, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there are exactly {@code count} VISIBLE components in the current UI match {@code block}. The {@link UI#getCurrent} and all of its descendants are searched. * @param clazz the component must be of this class. * @param count this count of components must match * @throws AssertionError if incorrect count of component matched. */ public static void _assert(@NotNull Class clazz, int count) { LocatorKt._expect(clazz, count, spec -> Unit.INSTANCE); } /** * Expects that there are exactly {@code count} VISIBLE components in the current UI of given class which matches spec. The {@link UI#getCurrent()} and all of its descendants are searched. * @param clazz the component must be of this class. * @param count this count of components must match * @param spec allows you to add search criterion. * @throws AssertionError if incorrect count of component matched. */ public static void _assert(@NotNull Class clazz, int count, @NotNull Consumer> spec) { LocatorKt._expect(clazz, count, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } /** * Expects that there are exactly {@code count} VISIBLE components of given class. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param count this count of components must match * @throws AssertionError if incorrect count of component matched. */ public static void _assert(@NotNull Component receiver, @NotNull Class clazz, int count) { LocatorKt._expect(receiver, clazz, count, ss -> Unit.INSTANCE); } /** * Expects that there are exactly {@code count} VISIBLE components of given class matching given spec. Given component and all of its descendants are searched. * @param receiver the parent layout to search in, not null. * @param clazz the component must be of this class. * @param count this count of components must match * @param spec allows you to add search criterion. * @throws AssertionError if incorrect count of component matched. */ public static void _assert(@NotNull Component receiver, @NotNull Class clazz, int count, @NotNull Consumer> spec) { LocatorKt._expect(receiver, clazz, count, ss -> { spec.accept(new SearchSpecJ<>(ss)); return Unit.INSTANCE; }); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy