From 41f130d65e7d6d12d670ab3f64b6d69af18aa3ca Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 24 Oct 2012 11:55:29 +0300 Subject: [PATCH] Made test understandable and ensure it passes by using timestamps Change-Id: Icf27faf2f884713f6e9c7d2fbd9e89b180cc85be --- .../tests/components/image/ImageClicks.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/uitest/src/com/vaadin/tests/components/image/ImageClicks.java b/uitest/src/com/vaadin/tests/components/image/ImageClicks.java index e50b8c3a4f..397e31c39c 100644 --- a/uitest/src/com/vaadin/tests/components/image/ImageClicks.java +++ b/uitest/src/com/vaadin/tests/components/image/ImageClicks.java @@ -7,7 +7,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Random; +import java.util.Date; import javax.imageio.ImageIO; @@ -20,8 +20,6 @@ import com.vaadin.ui.Label; public class ImageClicks extends TestBase { - private final Random rng = new Random(0); - private int clickCounter = 0; @Override @@ -30,7 +28,7 @@ public class ImageClicks extends TestBase { final Label label = new Label(labelText()); addComponent(label); - Image image = new Image(); + final Image image = new Image(); final MyImageSource imageSource = new MyImageSource(); final StreamResource imageResource = new StreamResource(imageSource, "testimage.png"); @@ -40,6 +38,9 @@ public class ImageClicks extends TestBase { @Override public void click(ClickEvent event) { ++clickCounter; + imageResource.setFilename("testimage.png?" + + new Date().getTime()); + image.markAsDirty(); label.setValue(labelText()); } @@ -58,7 +59,7 @@ public class ImageClicks extends TestBase { @Override protected String getDescription() { - return "Test click event handling of images"; + return "Each click on the dynamically generated image should update the image and add another black square"; } @Override @@ -110,11 +111,13 @@ public class ImageClicks extends TestBase { } // Cell - if (rng.nextFloat() < 0.5f) { - drawable.setColor(Color.white); - } else { + int cellIndex = col + row * cols; + if (clickCounter > cellIndex) { drawable.setColor(Color.black); + } else { + drawable.setColor(Color.white); } + drawable.fillRect(gridx + 1, gridy + 1, gridxnext - gridx - 1, gridynext - gridy - 1); } -- 2.39.5