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

org.loadui.testfx.controls.impl.HasLabelMatcher Maven / Gradle / Ivy

The newest version!
package org.loadui.testfx.controls.impl;

import javafx.scene.control.Labeled;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.internal.matchers.TypeSafeMatcher;

import static org.loadui.testfx.GuiTest.find;

public class HasLabelMatcher extends TypeSafeMatcher
{
	private final Matcher matcher;

	public HasLabelMatcher( Matcher matcher )
	{
		this.matcher = matcher;
	}

	public void describeTo( Description desc )
	{
		desc.appendText( "Node should match " + matcher );
	}

	@Override
	public boolean matchesSafely( Object target )
	{
		if( target instanceof String )
		{
			return matcher.matches(((Labeled) find( (String) target )).getText() );
		} else if( target instanceof Labeled )
		{
			return matcher.matches( ((Labeled) target).getText() );
		}
		return false;
	}
}