Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Assertions.java 1.73 KiB
Newer Older
package framework.common;

import com.microsoft.playwright.Locator;
import com.microsoft.playwright.assertions.PlaywrightAssertions;

import java.time.LocalDate;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class Assertions {

    /**
     * This method asserts that two collections are equal.
     *
     * @param expected expected collection.
     * @param actual   actual collection.
     * @param <T>      collection type.
     */
    public static <T> void assertEqualCollections(Collection<T> expected, Collection<T> actual) {
        assertEquals("The collections are different in size: ", expected.size(), actual.size());
        expected.forEach(element -> assertTrue("Expected element " + element + " not found in actual collection",
                actual.contains(element)));
    }

    /**
     * This method verifies that a given date is in a wished range.
     *
     * @param startDate start date of the range.
     * @param endDate   end date of the range.
     * @param date      date that is wanted for verification.
     */
    public static void assertDateIsInRange(LocalDate startDate, LocalDate endDate, LocalDate date) {
        assertTrue("The chosen date is before the start of the range", date.isAfter(startDate) || date.equals(startDate));
        assertTrue("The chosen date is after the end of the range", date.isBefore(endDate) || date.equals(endDate));
    }

    /**
     * This method verifies that an element is visible.
     *
     * @param locator Locator object wanted for visibility verification.
     */
    public static void assertElementIsVisibleByLocator(Locator locator) {
        PlaywrightAssertions.assertThat(locator).isVisible();
    }
    
}