2018-01-30 08:15:20 -05:00
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
import java.awt.AWTException;
|
|
|
|
import java.awt.Point;
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
class CursorTest {
|
|
|
|
|
|
|
|
Cursor cursor;
|
2018-01-30 10:04:20 -05:00
|
|
|
double cursorTolerance;
|
2018-01-30 08:15:20 -05:00
|
|
|
|
|
|
|
void initialize() throws AWTException {
|
|
|
|
cursor = new Cursor();
|
2018-01-30 10:04:20 -05:00
|
|
|
cursorTolerance = 3;
|
2018-01-30 08:15:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-01-30 10:04:20 -05:00
|
|
|
void testMoveCursorToCoordinatesHelper() throws InterruptedException, AWTException {
|
2018-01-30 08:15:20 -05:00
|
|
|
initialize();
|
2018-01-31 00:45:08 -05:00
|
|
|
testMoveCursorToCoordinates();
|
|
|
|
testRightClickCursor();
|
|
|
|
}
|
|
|
|
|
2018-02-12 19:40:09 -05:00
|
|
|
@Test
|
|
|
|
void testThetaBetweenPoints() {
|
|
|
|
Point a = new Point(0, 0);
|
|
|
|
Point b = new Point(10, 0);
|
|
|
|
Point c = new Point(10, 10);
|
|
|
|
Point d = new Point(20, 10);
|
|
|
|
assertEquals(cursor.getThetaBetweenPoints(a, b), 0);
|
|
|
|
}
|
|
|
|
|
2018-01-31 00:45:08 -05:00
|
|
|
void testMoveCursorToCoordinates() throws InterruptedException {
|
2018-01-30 08:15:20 -05:00
|
|
|
Point a = new Point(0, 0);
|
2018-01-30 10:04:20 -05:00
|
|
|
Point b = new Point(150, 250);
|
|
|
|
Point c = new Point(375, 190);
|
|
|
|
Point d = new Point(375, 600);
|
|
|
|
Point e = new Point(952, 603);
|
|
|
|
Point f = new Point(1025, 133);
|
|
|
|
Point g = new Point(543, 582);
|
|
|
|
testMoveCursorToCoordinates(a, b);
|
|
|
|
testMoveCursorToCoordinates(b, c);
|
|
|
|
testMoveCursorToCoordinates(c, d);
|
|
|
|
testMoveCursorToCoordinates(d, e);
|
|
|
|
testMoveCursorToCoordinates(e, f);
|
|
|
|
testMoveCursorToCoordinates(f, g);
|
|
|
|
testMoveCursorToCoordinates(g, c);
|
|
|
|
testMoveCursorToCoordinates(c, f);
|
|
|
|
testMoveCursorToCoordinates(f, b);
|
|
|
|
testMoveCursorToCoordinates(b, a);
|
2018-01-31 00:45:08 -05:00
|
|
|
testMoveCursorToCoordinates(a, g);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testRightClickCursor() throws InterruptedException {
|
|
|
|
Point a = new Point(375, 600);
|
|
|
|
Point b = new Point(952, 603);
|
|
|
|
Point c = new Point(1025, 133);
|
|
|
|
Point d = new Point(543, 582);
|
|
|
|
testMoveAndRightClickCursor(a, b);
|
|
|
|
testMoveAndRightClickCursor(b, c);
|
|
|
|
testMoveAndRightClickCursor(c, d);
|
|
|
|
testMoveAndRightClickCursor(d, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testMoveAndRightClickCursor(Point a, Point b) throws InterruptedException {
|
|
|
|
cursor.robotMouseMove(a);
|
|
|
|
cursor.moveAndRightClickAtCoordinates(b);
|
|
|
|
Point point = cursor.getCurrentCursorPoint();
|
|
|
|
verifyCursorIsInCorrectPlace(point, b);
|
|
|
|
// Way to verify that context menu is open?
|
2018-01-30 08:15:20 -05:00
|
|
|
}
|
|
|
|
|
2018-01-30 10:04:20 -05:00
|
|
|
void testMoveCursorToCoordinates(Point a, Point b) throws InterruptedException {
|
|
|
|
cursor.robotMouseMove(a);
|
|
|
|
cursor.moveCursorToCoordinates(b);
|
|
|
|
Point point = cursor.getCurrentCursorPoint();
|
|
|
|
verifyCursorIsInCorrectPlace(point, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void verifyCursorIsInCorrectPlace(Point actualPoint, Point expectedPoint) {
|
|
|
|
assertInRangeByAbsoluteValue(actualPoint.x, expectedPoint.x, cursorTolerance);
|
|
|
|
assertInRangeByAbsoluteValue(actualPoint.y, expectedPoint.y, cursorTolerance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void assertInRangeByPercentage(double valueToTest, double expectation, double tolerancePercentage) {
|
|
|
|
assertTrue((valueToTest <= (expectation * (1 + tolerancePercentage))) && (valueToTest >= (expectation * (1 - tolerancePercentage))));
|
|
|
|
}
|
|
|
|
|
|
|
|
void assertInRangeByAbsoluteValue(double valueToTest, double expectation, double toleranceAbsolute) {
|
|
|
|
assertTrue((valueToTest <= (expectation + toleranceAbsolute)) && (valueToTest >= (expectation * (1 - toleranceAbsolute))));
|
2018-01-30 08:15:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|