diff options
author | Artur Signell <artur@vaadin.com> | 2013-10-07 19:56:43 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-10-08 15:27:07 +0300 |
commit | 5fb877b093e4b2a9ddc98d558fe92f66d26af149 (patch) | |
tree | b8e71b7068b241e184d547f17196d8d57b196fb6 /uitest/src/com/vaadin/tests/tb3 | |
parent | f488825d46c984cea841534178b094be3a562eea (diff) | |
download | vaadin-framework-5fb877b093e4b2a9ddc98d558fe92f66d26af149.tar.gz vaadin-framework-5fb877b093e4b2a9ddc98d558fe92f66d26af149.zip |
Makes test stable and adds helper comparison methods
* Takes into account that the timer can be triggered multiple times before the initial request is done (especially if the server is slow)
* Adds assertLessThan, assertLessThanOrEqual, assertGreaterThan, assertGreaterThanOrEqual to ease test creation
Change-Id: I5ce1681e35d9c1de02a83b38528f17ee705331d7
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
-rw-r--r-- | uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 5c4ee01d5f..38c5b29bf9 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -325,6 +325,86 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** + * Asserts that {@literal a} is >= {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertGreaterOrEqual(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) >= 0) { + return; + } + + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is > {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertGreater(String message, Comparable<T> a, + T b) throws AssertionError { + if (a.compareTo(b) > 0) { + return; + } + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is <= {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertLessThanOrEqual(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) <= 0) { + return; + } + + throw new AssertionError(decorate(message, a, b)); + } + + /** + * Asserts that {@literal a} is < {@literal b} + * + * @param message + * The message to include in the {@link AssertionError} + * @param a + * @param b + * @throws AssertionError + * If comparison fails + */ + public static final <T> void assertLessThan(String message, + Comparable<T> a, T b) throws AssertionError { + if (a.compareTo(b) < 0) { + return; + } + throw new AssertionError(decorate(message, a, b)); + } + + private static <T> String decorate(String message, Comparable<T> a, T b) { + message = message.replace("{0}", a.toString()); + message = message.replace("{1}", b.toString()); + return message; + } + + /** * Returns the path that should be used for the test. The path contains the * full path (appended to hostname+port) and must start with a slash. * |