Skip to content

Commit

Permalink
Merged #37
Browse files Browse the repository at this point in the history
  • Loading branch information
minisu committed Jan 9, 2014
1 parent 40b25b7 commit f82ffc4
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 38 deletions.
30 changes: 13 additions & 17 deletions src/main/java/org/loadui/testfx/GuiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
import com.google.common.base.Predicates;
import com.google.common.collect.*;
import com.google.common.util.concurrent.SettableFuture;

import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.PopupWindow;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;

import org.hamcrest.Matcher;
import org.junit.Before;
import org.loadui.testfx.exceptions.NoNodesFoundException;
Expand All @@ -46,6 +45,7 @@
import org.loadui.testfx.utils.TestUtils;

import javax.imageio.ImageIO;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
Expand All @@ -61,13 +61,11 @@
import static org.loadui.testfx.utils.FXTestUtils.flattenSets;
import static org.loadui.testfx.utils.FXTestUtils.intersection;
import static org.loadui.testfx.utils.FXTestUtils.isVisible;
import static org.loadui.testfx.controls.Commons.hasLabel;

public abstract class GuiTest
{
private static final SettableFuture<Stage> stageFuture = SettableFuture.create();
protected static Stage stage;
private static String stylesheet = null;

public static class TestFxApp extends Application
{
Expand Down Expand Up @@ -105,8 +103,7 @@ private void showNodeInStage()

private void showNodeInStage( final String stylesheet )
{
GuiTest.stylesheet = stylesheet;

// TODO: Do something with the stylesheet?
if( stage == null )
{
FXTestUtils.launchApp(TestFxApp.class);
Expand Down Expand Up @@ -151,10 +148,6 @@ public void run()

public static <T extends Window> T targetWindow( T window )
{
if( window instanceof Stage )
{
Stage stage = ( Stage )window;
}
lastSeenWindow = window;
return window;
}
Expand Down Expand Up @@ -443,7 +436,8 @@ public Boolean call() throws Exception
}, timeoutInSeconds );
}

private static <T extends Node> T findByCssSelector( final String selector )
@SuppressWarnings("unchecked")
private static <T extends Node> T findByCssSelector( final String selector )
{
Set<Node> locallyFound = findAll( selector );
Iterable<Node> globallyFound = concat( transform( getWindows(),
Expand All @@ -463,7 +457,8 @@ public Iterable<Node> apply( Window input )
return ( T )getFirst( visibleNodes, null );
}

public static <T extends Node> T find( final Matcher<Object> matcher )
@SuppressWarnings("unchecked")
public static <T extends Node> T find( final Matcher<Object> matcher )
{
Iterable<Set<Node>> found = transform( getWindows(),
new Function<Window, Set<Node>>()
Expand Down Expand Up @@ -515,7 +510,7 @@ public static Set<Node> findAll( Matcher<Object> matcher, Node parent )

private static Set<Node> findAllRecursively( Matcher<Object> matcher, Node parent)
{
Set<Node> found = new HashSet();
Set<Node> found = new HashSet<Node>();
if( matcher.matches( parent ) )
{
found.add(parent);
Expand All @@ -539,8 +534,9 @@ public static <T extends Node> Set<T> findAll( Predicate<T> predicate, Node pare

private static <T extends Node> Set<T> findAllRecursively( Predicate<T> predicate, Node parent)
{
Set<T> found = new HashSet();
Set<T> found = new HashSet<T>();
try {
@SuppressWarnings("unchecked")
T node = (T) parent;
if( predicate.apply( node ) )
{
Expand Down Expand Up @@ -1194,11 +1190,11 @@ else if( target instanceof Window )
}
else if( target instanceof Matcher )
{
return pointFor( find( ( Matcher )target ) );
return pointFor( find( ( Matcher<Object> )target ) );
}
else if( target instanceof Predicate )
{
return pointFor( find( (Predicate) target ) );
return pointFor( find( (Predicate<Node>) target ) );
}
else if( target instanceof Iterable<?> )
{
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/loadui/testfx/controls/ListViews.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.scene.Node;
import javafx.scene.control.ListView;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
Expand Down Expand Up @@ -33,8 +34,9 @@ public static int numberOfRowsIn(String listQuery)
return table.getItems().size();
}

@SuppressWarnings("unchecked")
@Factory
public static org.hamcrest.Matcher containsRow(Object rowValue)
public static <S> org.hamcrest.Matcher<S> containsRow(Object rowValue)
{
return new ListContainsMatcher(rowValue);
}
Expand All @@ -58,6 +60,7 @@ static ListView<?> getListView(String listSelector) {
return (ListView<?>) node;
}

@SuppressWarnings("rawtypes")
private static class ListContainsMatcher extends BaseMatcher {
private Object valueToMatch;

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/loadui/testfx/controls/TableViews.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.loadui.testfx.controls;

import com.google.common.base.Predicate;

import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;
Expand Down Expand Up @@ -50,15 +52,16 @@ public static int numberOfRowsIn(String tableQuery)
return table.getItems().size();
}

@SuppressWarnings("unchecked")
@Factory
public static Matcher containsCell(Object cellValue)
public static <S> Matcher<S> containsCell(Object cellValue)
{
return new TableContainsMatcher(cellValue);
}

static boolean containsCell(TableView<?> table, Predicate<String> cellPredicate)
{
for( TableColumn column : table.getColumns() )
for( TableColumn<?, ?> column : table.getColumns() )
{
for(int i=0; i<table.getItems().size(); i++ )
{
Expand All @@ -72,7 +75,7 @@ static boolean containsCell(TableView<?> table, Predicate<String> cellPredicate)

static boolean containsCell(TableView<?> table, Object cellValue)
{
for( TableColumn column : table.getColumns() )
for( TableColumn<?, ?> column : table.getColumns() )
{
for(int i=0; i<table.getItems().size(); i++ )
{
Expand Down Expand Up @@ -154,6 +157,7 @@ protected static TableRow<?> row(String tableSelector, int row) {
}
}

@SuppressWarnings("rawtypes")
private static class TableContainsMatcher extends BaseMatcher
{
private Object valueToMatch;
Expand All @@ -163,6 +167,7 @@ public TableContainsMatcher(Object valueToMatch)
this.valueToMatch = valueToMatch;
}

@SuppressWarnings("unchecked")
@Override
public boolean matches(Object o) {
if( o instanceof String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.junit.internal.matchers.TypeSafeMatcher;

import static org.loadui.testfx.GuiTest.find;
import static com.google.common.base.Preconditions.checkArgument;

public class HasLabelMatcher extends TypeSafeMatcher<Object>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class NoNodesFoundException extends NodeQueryException
{
public NoNodesFoundException(String message)
private static final long serialVersionUID = 1L;

public NoNodesFoundException(String message)
{
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.loadui.testfx.exceptions;

public class NoNodesVisibleException extends NodeQueryException {
private static final long serialVersionUID = 1L;

public NoNodesVisibleException(String message)
{
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public abstract class NodeQueryException extends RuntimeException
{
private static final long serialVersionUID = 1L;

public NodeQueryException(String message)
{
super(message);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/loadui/testfx/utils/FXTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.BoundingBox;
Expand All @@ -37,6 +37,7 @@
import javafx.stage.Stage;

import com.google.common.util.concurrent.SettableFuture;

import org.loadui.testfx.GuiTest;

public class FXTestUtils
Expand Down Expand Up @@ -233,6 +234,7 @@ public boolean apply(javafx.scene.Node node) {
}
};

@SuppressWarnings("deprecation")
public static boolean isNodeVisible(Node node)
{
if(!node.isVisible() || !node.impl_isTreeVisible())
Expand Down
1 change: 0 additions & 1 deletion src/test/java/org/loadui/testfx/DragDropTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ protected Parent getRootNode() {
return HBoxBuilder.create().children(list1, list2).build();
}

@SuppressWarnings("unchecked")
@Test(timeout=10000)
public void shouldMoveElements() throws Exception {

Expand Down
8 changes: 0 additions & 8 deletions src/test/java/org/loadui/testfx/ListViewsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@
*/
package org.loadui.testfx;

import com.google.common.base.Predicate;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBoxBuilder;
import javafx.util.Callback;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.loadui.testfx.GuiTest;
Expand Down
6 changes: 1 addition & 5 deletions src/test/java/org/loadui/testfx/TableViewsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
import javafx.scene.layout.VBoxBuilder;
import javafx.util.Callback;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.loadui.testfx.categories.TestFX;
import org.loadui.testfx.controls.Commons;
import org.loadui.testfx.controls.TableViews;

import static javafx.collections.FXCollections.observableArrayList;
import static org.hamcrest.CoreMatchers.is;
Expand Down Expand Up @@ -68,7 +64,7 @@ protected Parent getRootNode()
@Override
public ObservableValue<Integer> call( TableColumn.CellDataFeatures<Integer, Integer> f )
{
return new SimpleObjectProperty( f.getValue() * 3 );
return new SimpleObjectProperty<Integer>( f.getValue() * 3 );
}
} );
table.getColumns().add( column );
Expand Down

0 comments on commit f82ffc4

Please sign in to comment.