PaintTest.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import drawing.PaintApplication;
  2. import javafx.scene.shape.Ellipse;
  3. import javafx.scene.shape.Rectangle;
  4. import javafx.stage.Stage;
  5. import org.junit.Test;
  6. import org.testfx.framework.junit.ApplicationTest;
  7. import java.util.Iterator;
  8. import static org.junit.Assert.*;
  9. public class PaintTest extends ApplicationTest {
  10. PaintApplication app;
  11. @Override
  12. public void start(Stage stage) {
  13. try {
  14. app = new PaintApplication();
  15. app.start(stage);
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. @Test
  21. public void should_draw_circle_programmatically() {
  22. interact(() -> {
  23. app.getDrawingPane().addShape(new Ellipse(20, 20, 30, 30));
  24. });
  25. Iterator it = app.getDrawingPane().getShapes().iterator();
  26. assertTrue(it.next() instanceof Ellipse);
  27. assertFalse(it.hasNext());
  28. }
  29. @Test
  30. public void should_draw_circle() {
  31. // given:
  32. clickOn("Circle");
  33. moveBy(60,60);
  34. // when:
  35. drag().dropBy(30,30);
  36. //press(MouseButton.PRIMARY); moveBy(30,30); release(MouseButton.PRIMARY);
  37. // then:
  38. Iterator it = app.getDrawingPane().getShapes().iterator();
  39. assertTrue(it.next() instanceof Ellipse);
  40. assertFalse(it.hasNext());
  41. }
  42. @Test
  43. public void should_draw_rectangle() {
  44. // given:
  45. clickOn("Rectangle");
  46. moveBy(0,60);
  47. // when:
  48. drag().dropBy(70,40);
  49. // then:
  50. Iterator it = app.getDrawingPane().getShapes().iterator();
  51. assertTrue(it.next() instanceof Rectangle);
  52. assertFalse(it.hasNext());
  53. }
  54. @Test
  55. public void should_clear() {
  56. // given:
  57. clickOn("Rectangle");
  58. moveBy(30,60).drag().dropBy(70,40);
  59. clickOn("Circle");
  60. moveBy(-30,160).drag().dropBy(70,40);
  61. // when:
  62. clickOn("Clear");
  63. // then:
  64. assertFalse(app.getDrawingPane().getShapes().iterator().hasNext());
  65. }
  66. }