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

org.loadui.testfx.Assertions Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
package org.loadui.testfx;

import com.google.common.base.Predicate;
import javafx.scene.Node;
import org.hamcrest.Matcher;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.loadui.testfx.GuiTest.find;

public class Assertions
{
	@SuppressWarnings( "unchecked" )
	public static void assertNodeExists( Matcher matcher )
	{
		find((Matcher) matcher);
	}

	public static void assertNodeExists( String query )
	{
		find(query);
	}

	public static  void verifyThat( T value, Matcher matcher )
	{
		verifyThat( "", value, matcher );
	}

	public static  void verifyThat( String reason, T value, Matcher matcher )
	{
		try
		{
			assertThat( reason, value, matcher );
		}
		catch( AssertionError e )
		{
			throw new AssertionError( e.getMessage() + " Screenshot saved as " + GuiTest.captureScreenshot().getAbsolutePath() , e );
		}
	}

    public static  void verifyThat( String query, Predicate predicate )
    {
            T node = find( query );
            if(! predicate.apply( node ) )
                throw new AssertionError( "Predicate failed for query '" + query + "'. Screenshot saved as " + GuiTest.captureScreenshot().getAbsolutePath() );
    }

    public static  void verifyThat( T node, Predicate predicate )
    {
            if(! predicate.apply( node ) )
                throw new AssertionError( "Predicate failed for '" + node + "'. Screenshot saved as " + GuiTest.captureScreenshot().getAbsolutePath() );
    }
}