<commit_before>package nl.tudelft.dnainator.javafx.views;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javafx.geometry.Point2D;
import javafx.stage.Stage;
import nl.tudelft.dnainator.javafx.ColorServer;
import nl.tudelft.dnainator.tree.TreeNode;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testfx.framework.junit.ApplicationTest;

/**
 * This class tests the implementation of the {@link PhylogeneticView}.
 * This is the view responsible for everything related to the phylogenetic tree.
 */
public class PhylogeneticViewTest extends ApplicationTest {

	private PhylogeneticView phyloView;
	private TreeNode tn;
	@Mock private ColorServer colorServer;
	
	@Override
	public void start(Stage stage) throws Exception {
	}
	
	/**
	 * Set up common variables.
	 */
	@Before
	public void setup() {
		tn = new TreeNode(null);
		MockitoAnnotations.initMocks(this);
		phyloView = new PhylogeneticView(colorServer, tn);	
	}
	
	/**
	 * Tests creating a {@link PhylogeneticView} with a tree containing two children.
	 */
	@Test
	public void testCreate() {
		tn.addChild(new TreeNode(tn));
		phyloView = new PhylogeneticView(colorServer, tn);
		// CHECKSTYLE.OFF: MagicNumber
		assertEquals(2, tn.getChildren().size());
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test zooming on the {@link PhylogeneticView}.
	 * Zooming out of bounds should not change the zoom.
	 */
	@Test
	public void testZoom() {
		double zoomPrevious = phyloView.scale.getMxx();
		
		// CHECKSTYLE.OFF: MagicNumber
		phyloView.zoom(1.0, new Point2D(1.0, 2.0));
		// CHECKSTYLE.ON: MagicNumber
		
		assertTrue(phyloView.scale.getMxx() > zoomPrevious);
		assertTrue(phyloView.scale.getMyy() > zoomPrevious);
		
		zoomPrevious = phyloView.scale.getMxx();
		// CHECKSTYLE.OFF: MagicNumber
		phyloView.zoom(Double.MAX_VALUE, new Point2D(1.0, 2.0));
		assertEquals(zoomPrevious, phyloView.scale.getMxx(), 0.001);
		assertEquals(zoomPrevious, phyloView.scale.getMyy(), 0.001);
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test the default scale of the {@link PhylogeneticView}.
	 */
	@Test
	public void testGetScale() {
		// CHECKSTYLE.OFF: MagicNumber
		assertEquals(0.1, phyloView.getScale().getMxx(), 0.001);
		assertEquals(0.1, phyloView.getScale().getMyy(), 0.001);
		// CHECKSTYLE.ON: MagicNumber
	}
}<commit_msg>Extend phylogeneticview test so that it also tests the controller.<commit_after>package nl.tudelft.dnainator.javafx.views;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Point2D;
import javafx.geometry.VerticalDirection;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import javafx.stage.Window;
import nl.tudelft.dnainator.javafx.ColorServer;
import nl.tudelft.dnainator.javafx.controllers.AbstractViewController;
import nl.tudelft.dnainator.tree.TreeNode;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.testfx.framework.junit.ApplicationTest;

import java.util.concurrent.TimeUnit;

/**
 * This class tests the implementation of the {@link PhylogeneticView}.
 * This is the view responsible for everything related to the phylogenetic tree.
 */
@RunWith(MockitoJUnitRunner.class)
public class PhylogeneticViewTest extends ApplicationTest {
	private static final int WIDTH = 800;
	private static final int HEIGHT = 600;
	private Window window;
	private AbstractViewController control;
	private PhylogeneticView view;
	@Mock private ColorServer colorServer;
	
	@Override
	public void start(Stage stage) throws Exception {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/view.fxml"));
		view = new PhylogeneticView(new ColorServer(), createTree());
		loader.setRoot(view);
		loader.load();

		Scene scene = new Scene(view, WIDTH, HEIGHT);
		stage.setScene(scene);
		stage.show();

		window = scene.getWindow();
		control = loader.getController();
	}
	
	/**
	 * Tests creating a {@link PhylogeneticView} with a tree containing two children.
	 */
	@Test
	public void testCreate() {
		TreeNode tree = createTree();
		view = new PhylogeneticView(colorServer, tree);
		// CHECKSTYLE.OFF: MagicNumber
		assertEquals(2, tree.getChildren().size());
		// CHECKSTYLE.ON: MagicNumber
	}

	/**
	 * Test zooming in by scrolling the mouse.
	 */
	@Test
	public void testOnScroll() {
		double zoomPrevious;

		zoomPrevious = view.scale.getMxx();
		moveTo(view).scroll(VerticalDirection.UP).sleep(1, TimeUnit.SECONDS);
		assertTrue(view.scale.getMxx() > zoomPrevious);
		assertTrue(view.scale.getMyy() > zoomPrevious);

		zoomPrevious = view.scale.getMxx();
		moveTo(view).scroll(VerticalDirection.DOWN).sleep(1, TimeUnit.SECONDS);
		assertTrue(view.scale.getMxx() < zoomPrevious);
		assertTrue(view.scale.getMyy() < zoomPrevious);
	}

	/**
	 * Test panning by dragging the screen.
	 */
	@Test
	public void testOnMouseDragged() {
		double prevX;

		prevX = view.translate.getX();
		drag(window.getX(), window.getY(), MouseButton.PRIMARY)
		.sleep(1, TimeUnit.MICROSECONDS)
		.dropTo(window.getX() + 2, window.getY())
		.sleep(1, TimeUnit.SECONDS);
		assertTrue(view.translate.getX() > prevX);

		prevX = view.translate.getX();
		drag(window.getX() + 2, window.getY(), MouseButton.PRIMARY)
		.sleep(1, TimeUnit.MICROSECONDS)
		.dropTo(window.getX(), window.getY())
		.sleep(1, TimeUnit.SECONDS);
		assertTrue(view.translate.getX() < prevX);
	}

	/**
	 * Test panning and zooming by using the keyboard.
	 */
	@Test
	public void testOnKeyPressed() {
		double prevX, prevY, prevZoom;

		prevX = view.translate.getX();
		clickOn(view).type(KeyCode.RIGHT);
		assertTrue(view.translate.getX() < prevX);

		prevX = view.translate.getX();
		clickOn(view).type(KeyCode.LEFT);
		assertTrue(view.translate.getX() > prevX);

		prevY = view.translate.getY();
		clickOn(view).type(KeyCode.DOWN);
		assertTrue(view.translate.getY() < prevY);

		prevY = view.translate.getY();
		clickOn(view).type(KeyCode.UP);
		assertTrue(view.translate.getY() > prevY);

		prevZoom = view.scale.getMxx();
		clickOn(view).type(KeyCode.PLUS);
		assertTrue(view.scale.getMxx() > prevZoom);
		assertTrue(view.scale.getMyy() > prevZoom);

		prevZoom = view.scale.getMxx();
		clickOn(view).type(KeyCode.MINUS);
		assertTrue(view.scale.getMxx() < prevZoom);
		assertTrue(view.scale.getMyy() < prevZoom);
	}

	/**
	 * Test zooming on the {@link PhylogeneticView}.
	 * Zooming out of bounds should not change the zoom.
	 */
	@Test
	public void testZoom() {
		double zoomPrevious = view.scale.getMxx();
		
		// CHECKSTYLE.OFF: MagicNumber
		view.zoom(1.0, new Point2D(1.0, 2.0));
		// CHECKSTYLE.ON: MagicNumber
		
		assertTrue(view.scale.getMxx() > zoomPrevious);
		assertTrue(view.scale.getMyy() > zoomPrevious);
		
		zoomPrevious = view.scale.getMxx();
		// CHECKSTYLE.OFF: MagicNumber
		view.zoom(Double.MAX_VALUE, new Point2D(1.0, 2.0));
		assertEquals(zoomPrevious, view.scale.getMxx(), 0.001);
		assertEquals(zoomPrevious, view.scale.getMyy(), 0.001);
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test the default scale of the {@link PhylogeneticView}.
	 */
	@Test
	public void testGetScale() {
		// CHECKSTYLE.OFF: MagicNumber
		assertEquals(0.1, view.getScale().getMxx(), 0.001);
		assertEquals(0.1, view.getScale().getMyy(), 0.001);
		// CHECKSTYLE.ON: MagicNumber
	}

	private TreeNode createTree() {
		TreeNode tree, child;
		tree = new TreeNode(null);
		child = new TreeNode(tree);
		child.setName("A");
		child = new TreeNode(tree);
		child.setName("B");

		return tree;
	}
}
{'fraction_non_alphanumeric': 0.13359223300970874, 'fraction_numerical': 0.010614886731391585, 'mean_word_length': 4.4677990092002835, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6207281', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2583, 'n_words': 555}