<commit_before>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.constants.Constants;
import au.com.agic.apptesting.utils.MouseMovementUtils;
import au.com.agic.apptesting.utils.SystemPropertyUtils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;
import java.awt.*;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Implementation of MouseMovementUtils
 */
@org.springframework.stereotype.Component
public class MouseMovementUtilsImpl implements MouseMovementUtils {
	private static final Logger LOGGER = LoggerFactory.getLogger(MouseMovementUtilsImpl.class);

	@Autowired
	private SystemPropertyUtils systemPropertyUtils;

	@Override
	public void mouseGlide(int x1, int y1, int x2, int y2, int time, int steps) {
		try {
			final Robot r = new Robot();

			final double dx = (x2 - x1) / ((double) steps);
			final double dy = (y2 - y1) / ((double) steps);
			final double dt = time / ((double) steps);
			for (int step = 1; step <= steps; step++) {
				Thread.sleep((int) dt);
				r.mouseMove((int) (x1 + dx * step), (int) (y1 + dy * step));
			}
		} catch (final AWTException | InterruptedException ex) {
			LOGGER.error("WEBAPPTESTER-BUG-0010: Exception thrown while moving mouse cursor", ex);
		}
	}

	@Override
	public void mouseGlide(int x2, int y2, int time, int steps) {
		final Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
		mouseGlide(mouseLocation.x, mouseLocation.y, x2, y2, time, steps);
	}

	@Override
	public void mouseGlide(@NotNull final JavascriptExecutor javascriptExecutor,
						   @NotNull final WebElement element,
						   int time,
						   int steps) {
		checkNotNull(element);

		final boolean moveMouseCursor =
			systemPropertyUtils.getPropertyAsBoolean(
				Constants.MOVE_CURSOR_TO_ELEMENT, false);

		if (moveMouseCursor) {

			final float zoom = systemPropertyUtils.getPropertyAsFloat(
				Constants.SCREEN_ZOOM_FACTOR, 1.0f);

			final org.openqa.selenium.Point viewPoint = element.getLocation();
			final Long height = (Long)javascriptExecutor.executeScript(
				"return arguments[0].clientHeight;", element);
			final Long width = (Long)javascriptExecutor.executeScript(
				"return arguments[0].clientWidth;", element);
			mouseGlide(
				(int)((viewPoint.x + width) * zoom),
				(int)((viewPoint.y + height) * zoom),
				Constants.MOUSE_MOVE_TIME,
				Constants.MOUSE_MOVE_STEPS);
		}
	}
}<commit_msg>Fixed up some logic for placing the mouse cursor<commit_after>package au.com.agic.apptesting.utils.impl;

import au.com.agic.apptesting.constants.Constants;
import au.com.agic.apptesting.utils.MouseMovementUtils;
import au.com.agic.apptesting.utils.SystemPropertyUtils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotNull;
import java.awt.*;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Implementation of MouseMovementUtils
 */
@org.springframework.stereotype.Component
public class MouseMovementUtilsImpl implements MouseMovementUtils {
	private static final Logger LOGGER = LoggerFactory.getLogger(MouseMovementUtilsImpl.class);

	@Autowired
	private SystemPropertyUtils systemPropertyUtils;

	@Override
	public void mouseGlide(int x1, int y1, int x2, int y2, int time, int steps) {
		try {
			final Robot r = new Robot();

			final double dx = (x2 - x1) / ((double) steps);
			final double dy = (y2 - y1) / ((double) steps);
			final double dt = time / ((double) steps);
			for (int step = 1; step <= steps; step++) {
				Thread.sleep((int) dt);
				r.mouseMove((int) (x1 + dx * step), (int) (y1 + dy * step));
			}
		} catch (final AWTException | InterruptedException ex) {
			LOGGER.error("WEBAPPTESTER-BUG-0010: Exception thrown while moving mouse cursor", ex);
		}
	}

	@Override
	public void mouseGlide(int x2, int y2, int time, int steps) {
		final Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
		mouseGlide(mouseLocation.x, mouseLocation.y, x2, y2, time, steps);
	}

	@Override
	public void mouseGlide(@NotNull final JavascriptExecutor javascriptExecutor,
						   @NotNull final WebElement element,
						   int time,
						   int steps) {
		checkNotNull(element);

		final boolean moveMouseCursor =
			systemPropertyUtils.getPropertyAsBoolean(
				Constants.MOVE_CURSOR_TO_ELEMENT, false);

		if (moveMouseCursor) {

			final float zoom = systemPropertyUtils.getPropertyAsFloat(
				Constants.SCREEN_ZOOM_FACTOR, 1.0f);

			final org.openqa.selenium.Point viewPoint = element.getLocation();
			final Long height = (Long)javascriptExecutor.executeScript(
				"return arguments[0].clientHeight;", element);
			final Long width = (Long)javascriptExecutor.executeScript(
				"return arguments[0].clientWidth;", element);
			mouseGlide(
				(int)((viewPoint.x + width / 2) * zoom),
				(int)((viewPoint.y + height / 2) * zoom),
				Constants.MOUSE_MOVE_TIME,
				Constants.MOUSE_MOVE_STEPS);
		}
	}
}
{'fraction_non_alphanumeric': 0.11172335170055102, 'fraction_numerical': 0.009880296408892267, 'mean_word_length': 4.489051094890511, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3837685', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1633, 'n_words': 396}