Skip to content

Commit

Permalink
(refactor) Rename window methods to targetWindow(), listWindows()
Browse files Browse the repository at this point in the history
…, and `window()`.
  • Loading branch information
hastebrot committed Dec 5, 2015
1 parent b168c6e commit db97b9e
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 112 deletions.
109 changes: 95 additions & 14 deletions subprojects/testfx-core/src/main/java/org/testfx/api/FxRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package org.testfx.api;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -78,7 +80,7 @@ public FxRobotContext robotContext() {

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot pos(Pos pointPosition) {
public FxRobot targetPos(Pos pointPosition) {
context.setPointPosition(pointPosition);
return this;
}
Expand Down Expand Up @@ -117,7 +119,7 @@ public PointQuery point(Bounds bounds) {
public PointQuery point(Node node) {
PointLocator pointLocator = context.getPointLocator();
Pos pointPosition = context.getPointPosition();
target(node.getScene().getWindow());
targetWindow(node.getScene().getWindow());
return pointLocator.pointFor(node).atPosition(pointPosition);
}

Expand All @@ -126,7 +128,7 @@ public PointQuery point(Node node) {
public PointQuery point(Scene scene) {
PointLocator pointLocator = context.getPointLocator();
Pos pointPosition = context.getPointPosition();
target(scene.getWindow());
targetWindow(scene.getWindow());
return pointLocator.pointFor(scene).atPosition(pointPosition);
}

Expand All @@ -135,7 +137,7 @@ public PointQuery point(Scene scene) {
public PointQuery point(Window window) {
PointLocator pointLocator = context.getPointLocator();
Pos pointPosition = context.getPointPosition();
target(window);
targetWindow(window);
return pointLocator.pointFor(window).atPosition(pointPosition);
}

Expand Down Expand Up @@ -218,8 +220,8 @@ public PointQuery offset(String query,
@Override
@Unstable(reason = "is missing apidocs; might change to accept all objects")
public <T extends Node> PointQuery offset(Matcher<T> matcher,
double offsetX,
double offsetY) {
double offsetX,
double offsetY) {
return point(matcher).atOffset(offsetX, offsetY);
}

Expand All @@ -237,32 +239,111 @@ public <T extends Node> PointQuery offset(Predicate<T> predicate,

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot target(Window window) {
context.getWindowFinder().target(window);
public Window targetWindow() {
return context.getWindowFinder().targetWindow();
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot targetWindow(Window window) {
context.getWindowFinder().targetWindow(window);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobotInterface targetWindow(Predicate<Window> predicate) {
context.getWindowFinder().targetWindow(predicate);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot targetWindow(int windowNumber) {
context.getWindowFinder().targetWindow(windowNumber);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot targetWindow(String stageTitleRegex) {
context.getWindowFinder().targetWindow(stageTitleRegex);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot target(int windowNumber) {
context.getWindowFinder().target(windowNumber);
public FxRobotInterface targetWindow(Pattern stageTitlePattern) {
context.getWindowFinder().targetWindow(stageTitlePattern);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot target(String stageTitleRegex) {
context.getWindowFinder().target(stageTitleRegex);
public FxRobot targetWindow(Scene scene) {
context.getWindowFinder().targetWindow(scene);
return this;
}

@Override
@Unstable(reason = "is missing apidocs")
public FxRobot target(Scene scene) {
context.getWindowFinder().target(scene);
public FxRobotInterface targetWindow(Node node) {
context.getWindowFinder().targetWindow(node);
return this;
}

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW LOOKUP.
//---------------------------------------------------------------------------------------------

@Override
@Unstable(reason = "is missing apidocs")
public List<Window> listWindows() {
return context.getWindowFinder().listWindows();
}

@Override
@Unstable(reason = "is missing apidocs")
public List<Window> listTargetWindows() {
return context.getWindowFinder().listTargetWindows();
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(Predicate<Window> predicate) {
return context.getWindowFinder().window(predicate);
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(int windowIndex) {
return context.getWindowFinder().window(windowIndex);
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(String stageTitleRegex) {
return context.getWindowFinder().window(stageTitleRegex);
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(Pattern stageTitlePattern) {
return context.getWindowFinder().window(stageTitlePattern);
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(Scene scene) {
return context.getWindowFinder().window(scene);
}

@Override
@Unstable(reason = "is missing apidocs")
public Window window(Node node) {
return context.getWindowFinder().window(node);
}

//---------------------------------------------------------------------------------------------
// METHODS FOR NODE LOOKUP.
//---------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.testfx.api;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
Expand All @@ -43,7 +45,7 @@ public interface FxRobotInterface {
// METHODS FOR POINT POSITION.
//---------------------------------------------------------------------------------------------

public FxRobotInterface pos(Pos pointPosition);
public FxRobotInterface targetPos(Pos pointPosition);

//---------------------------------------------------------------------------------------------
// METHODS FOR POINT LOCATION.
Expand Down Expand Up @@ -98,25 +100,31 @@ public <T extends Node> PointQuery offset(Predicate<T> predicate,
// METHODS FOR WINDOW TARGETING.
//---------------------------------------------------------------------------------------------

public FxRobotInterface target(Window window);
public FxRobotInterface target(int windowNumber);
public FxRobotInterface target(String stageTitleRegex);
public Window targetWindow();
public FxRobotInterface targetWindow(Window window);
public FxRobotInterface targetWindow(Predicate<Window> predicate);

// Convenience methods:
public FxRobotInterface target(Scene scene);
public FxRobotInterface targetWindow(int windowIndex);
public FxRobotInterface targetWindow(String stageTitleRegex);
public FxRobotInterface targetWindow(Pattern stageTitlePattern);
public FxRobotInterface targetWindow(Scene scene);
public FxRobotInterface targetWindow(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW LOOKUP.
//---------------------------------------------------------------------------------------------

//public List<Window> listWindows();
//public List<Window> listTargetWindows();

//public Window window(int windowIndex);
//public Window window(String stageTitleRegex);
public List<Window> listWindows();
public List<Window> listTargetWindows();
public Window window(Predicate<Window> predicate);

// Convenience methods:
//public Window window(Scene scene);
public Window window(int windowIndex);
public Window window(String stageTitleRegex);
public Window window(Pattern stageTitlePattern);
public Window window(Scene scene);
public Window window(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR NODE LOOKUP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void write(String text) {
//---------------------------------------------------------------------------------------------

private void pushCharacter(char character) {
Scene scene = windowFinder.target().getScene();
Scene scene = windowFinder.targetWindow().getScene();
KeyCode key = determineKeyCode(character);
baseRobot.typeKeyboard(scene, key, Character.toString(character));
baseRobot.awaitEvents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,43 @@
package org.testfx.service.finder;

import java.util.List;
import java.util.regex.Pattern;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.stage.Window;

import com.google.common.base.Predicate;

public interface WindowFinder {
public Window target();
public void target(Window window);
public void target(int windowIndex);
public void target(String stageTitleRegex);
public void target(Scene scene);
//public void target(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW TARGETING.
//---------------------------------------------------------------------------------------------

public Window targetWindow();
public void targetWindow(Window window);
public void targetWindow(Predicate<Window> predicate);

// Convenience methods:
public void targetWindow(int windowIndex);
public void targetWindow(String stageTitleRegex);
public void targetWindow(Pattern stageTitlePattern);
public void targetWindow(Scene scene);
public void targetWindow(Node node);

//---------------------------------------------------------------------------------------------
// METHODS FOR WINDOW LOOKUP.
//---------------------------------------------------------------------------------------------

public List<Window> listWindows();
public List<Window> listOrderedWindows();
public List<Window> listTargetWindows();
public Window window(Predicate<Window> predicate);

// Convenience methods:
public Window window(int windowIndex);
public Window window(String stageTitleRegex);
public Window window(Pattern stageTitlePattern);
public Window window(Scene scene);
//public Window window(Node node);
public Window window(Node node);

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Node rootNode(Node node) {
//---------------------------------------------------------------------------------------------

private Set<Node> rootsOfWindows() {
List<Window> windows = windowFinder.listOrderedWindows();
List<Window> windows = windowFinder.listTargetWindows();
return NodeQueryUtils.rootsOfWindows(windows);
}

Expand Down

0 comments on commit db97b9e

Please sign in to comment.