public class TestUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
assertArrayEqual(byte[] expected,
byte[] actual)
Asserts that the given byte arrays are equal
|
static void |
assertArrayEqual(byte[] expected,
byte[] actual,
String errorMessage)
Asserts that the given byte arrays are equal
|
static void |
assertArrayEqual(double[] expected,
double[] actual,
double maxRelativeError)
Asserts that the given double arrays are equal
|
static void |
assertArrayEqual(double[] expected,
double[] actual,
double maxRelativeError,
String errorMessage)
Asserts that the given double arrays are equal
|
static void |
assertArrayEqual(float[] expected,
float[] actual,
double maxRelativeError)
Asserts that the given float arrays are equal
|
static void |
assertArrayEqual(float[] expected,
float[] actual,
double maxRelativeError,
String errorMessage)
Asserts that the given double arrays are equal
|
static void |
assertArrayEqual(int[] expected,
int[] actual)
Asserts that the given int arrays are equal
|
static void |
assertArrayEqual(int[] expected,
int[] actual,
String errorMessage)
Asserts that the given int arrays are equal
|
static void |
assertArrayEqual(long[] expected,
long[] actual,
double maxRelativeError)
Asserts that the given long arrays are equal
|
static void |
assertArrayEqual(long[] expected,
long[] actual,
double maxRelativeError,
String errorMessage)
Asserts that the given long arrays are equal
|
static void |
assertArrayEqual(Object[] expected,
Object[] actual)
Asserts that the given object arrays are equal
|
static void |
assertArrayEqual(Object[] expected,
Object[] actual,
String errorMessage)
Asserts that the given object arrays are equal
|
static void |
assertArrayEqual(short[] expected,
short[] actual)
Asserts that the given short arrays are equal
|
static void |
assertArrayEqual(short[] expected,
short[] actual,
String errorMessage)
Asserts that the given short arrays are equal
|
static void |
assertBool(boolean b)
Assertions allow for simpler test code
|
static void |
assertBool(boolean b,
String errorMessage)
Assertions allow for simpler test code
|
static void |
assertEqual(byte expected,
byte actual)
Asserts that the given bytes are equal
|
static void |
assertEqual(byte expected,
byte actual,
String errorMessage)
Asserts that the given bytes are equal
|
static void |
assertEqual(double expected,
double actual,
double maxRelativeError)
Asserts that the given doubles are equal
|
static void |
assertEqual(double expected,
double actual,
double maxRelativeError,
String errorMessage)
Asserts that the given doubles are equal
|
static void |
assertEqual(float expected,
float actual,
double maxRelativeError)
Asserts that the given floats are equal
|
static void |
assertEqual(float expected,
float actual,
double maxRelativeError,
String errorMessage)
Asserts that the given floats are equal
|
static void |
assertEqual(int expected,
int actual)
Asserts that the given ints are equal
|
static void |
assertEqual(int expected,
int actual,
String errorMessage)
Asserts that the given ints are equal
|
static void |
assertEqual(long expected,
long actual)
Asserts that the given longs are equal
|
static void |
assertEqual(long expected,
long actual,
String errorMessage)
Asserts that the given longs are equal
|
static void |
assertEqual(Object expected,
Object actual)
Asserts that the given objects are equal using the first object's .equal() method
|
static void |
assertEqual(Object expected,
Object actual,
String errorMessage)
Asserts that the given objects are equal using the first object's .equal() method
|
static void |
assertEqual(short expected,
short actual)
Asserts that the given shorts are equal
|
static void |
assertEqual(short expected,
short actual,
String errorMessage)
Asserts that the given shorts are equal
|
static void |
assertException(RuntimeException exception,
Runnable expression)
Asserts that a certain exception is raised
|
static void |
assertException(RuntimeException exception,
Runnable expression,
String errorMessage)
Asserts that a certain exception is raised
|
static void |
assertFalse(boolean value)
Asserts that the given expression evaluates to false
|
static void |
assertFalse(boolean value,
String errorMessage)
Asserts that the given expression evaluates to false
|
static void |
assertLabel(int[] path,
String text)
Asserts that we have a label with the given text baring the given name
|
static void |
assertLabel(String text)
Asserts that we have a label with the given text baring the given name
|
static void |
assertLabel(String name,
String text)
Asserts that we have a label with the given text baring the given name
|
static void |
assertNoException(Runnable expression)
Asserts that no exception is raised
|
static void |
assertNoException(Runnable expression,
String errorMessage)
Asserts that no exception is raised
|
static void |
assertNotEqual(byte expected,
byte actual)
Asserts that the given bytes are not equal
|
static void |
assertNotEqual(byte expected,
byte actual,
String errorMessage)
Asserts that the given bytes are not equal
|
static void |
assertNotEqual(double expected,
double actual,
double minRelativeError)
Asserts that the given doubles are not equal
|
static void |
assertNotEqual(double expected,
double actual,
double minRelativeError,
String errorMessage)
Asserts that the given doubles are not equal
|
static void |
assertNotEqual(int expected,
int actual)
Asserts that the given ints are not equal
|
static void |
assertNotEqual(int expected,
int actual,
String errorMessage)
Asserts that the given ints are not equal
|
static void |
assertNotEqual(long expected,
long actual,
double minRelativeError)
Asserts that the given longs are not equal
|
static void |
assertNotEqual(long expected,
long actual,
double minRelativeError,
String errorMessage)
Asserts that the given longs are not equal
|
static void |
assertNotEqual(Object expected,
Object actual)
Asserts that the given objects are not equal using the first object's .equal() method
|
static void |
assertNotEqual(Object expected,
Object actual,
String errorMessage)
Asserts that the given objects are not equal using the first object's .equal() method
|
static void |
assertNotEqual(short expected,
short actual)
Asserts that the given shorts are not equal
|
static void |
assertNotEqual(short expected,
short actual,
String errorMessage)
Asserts that the given shorts are not equal
|
static void |
assertNotNull(Object object)
Asserts that the given expression does not evaluate to null
|
static void |
assertNotNull(Object object,
String errorMessage)
Asserts that the given expression does not evaluate to null
|
static void |
assertNotSame(Object expected,
Object actual)
Asserts that the given parameters do not reference the same object
|
static void |
assertNotSame(Object expected,
Object actual,
String errorMessage)
Asserts that the given parameters do not reference the same object
|
static void |
assertNull(Object object)
Asserts that the given expression evaluates to null
|
static void |
assertNull(Object object,
String errorMessage)
Asserts that the given expression evaluates to null
|
static void |
assertRange(double expected,
double actual,
double absoluteError)
Asserts that the given doubles are equal
|
static void |
assertRange(double expected,
double actual,
double maxAbsoluteError,
String errorMessage)
Asserts that the given doubles are equal
|
static void |
assertSame(Object expected,
Object actual)
Asserts that the given parameters reference the same object
|
static void |
assertSame(Object expected,
Object actual,
String errorMessage)
Asserts that the given parameters reference the same object
|
static void |
assertTextArea(int[] path,
String text)
Asserts that we have a label with the given text baring the given name
|
static void |
assertTextArea(String text)
Asserts that we have a label with the given text baring the given name
|
static void |
assertTextArea(String name,
String text)
Asserts that we have a TextArea with the given text and the given name
|
static void |
assertTextAreaContaining(String name,
String text)
Asserts that we have a TextArea with the a text contains the given text and with the given name
|
static void |
assertTextAreaEndingWith(String name,
String text)
Asserts that we have a TextArea with the a text ending with the given text and with the given name
|
static void |
assertTextAreaStartingWith(String name,
String text)
Asserts that we have a TextArea with the a text starting with the given text and with the given name
|
static void |
assertTitle(String title)
Verifies the current title is the same otherwise throws an exception
|
static void |
assertTrue(boolean value)
Asserts that the given expression evaluates to true
|
static void |
assertTrue(boolean value,
String errorMessage)
Asserts that the given expression evaluates to true
|
static void |
clickButtonByLabel(String text)
Clicks the button with the given label
|
static void |
clickButtonByName(String name)
Clicks the button with the given label
|
static void |
clickButtonByPath(int[] path)
Clicks the button with the given component path
|
static void |
clickMenuItem(String name)
Executes a menu command with the given name
|
static void |
ensureVisible(Component c)
Scrolls to show the component in case it is invisible currently
|
static void |
ensureVisible(int[] path)
Scrolls to show the component in case it is invisible currently
|
static void |
ensureVisible(String componentName)
Scrolls to show the component in case it is invisible currently
|
static void |
executeToolbarCommandAtOffset(int offset)
Executes a command from the offset returned by
getToolbarCommands() |
static void |
fail()
An assertion that always fails a test.
|
static void |
fail(String errorMessage)
An assertion that always fails a test.
|
static Component |
findByName(String componentName)
Finds a component with the given name, works even with UI's that weren't created with the GUI builder
|
static Label |
findLabelText(String text)
Finds a component with the given name, works even with UI's that weren't created with the GUI builder
|
static TextArea |
findTextAreaText(String text)
Finds a component with the given name, works even with UI's that weren't created with the GUI builder
|
static void |
gameKeyPress(int gameKey)
Simulates a game key press
|
static void |
gameKeyRelease(int gameKey)
Simulates a game key release
|
static Component |
getComponentByPath(int[] path)
Gets the component from the current form based on its path.
|
static Command[] |
getToolbarCommands()
Returns all the command objects from the toolbar in the order of left, right, overflow & sidemenu
|
static void |
goBack()
Executes the back command for the current form, similarly to pressing the back button
|
static void |
keyPress(int keyCode)
Simulates a device key press
|
static void |
keyRelease(int keyCode)
Simulates a device key release
|
static void |
log(String t)
Log to the test log
|
static void |
log(Throwable t)
Log to the test log
|
static void |
pointerDrag(float x,
float y,
int[] path)
A component drag on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static void |
pointerDrag(float x,
float y,
String componentName)
A component drag on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static void |
pointerPress(float x,
float y,
int[] path)
A component press on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static void |
pointerPress(float x,
float y,
String componentName)
A component press on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static void |
pointerRelease(float x,
float y,
int[] path)
A component release on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static void |
pointerRelease(float x,
float y,
String componentName)
A component release on a given named component at x/y where x and y are NOT pixels
but rather a number between 0 to 1 representing the percentage within the component where the
event took place.
|
static boolean |
screenshotTest(String screenshotName)
The screenshot test takes a screenshot of the screen and compares it to
a prior screenshot, if both are 100% identical the test passes.
|
static void |
selectInList(int[] path,
int offset)
Selects the given offset in a list
|
static void |
selectInList(String listName,
int offset)
Selects the given offset in a list
|
static void |
setText(int[] path,
String text)
Sets the text for the given component
|
static void |
setText(String name,
String text)
Sets the text for the given component
|
static void |
setVerboseMode(boolean v)
Activates/deactivates the verbose test mode
|
static void |
showSidemenu()
Shows the sidemenu UI
|
static void |
waitFor(int millis)
Waits for the given number of milliseconds even if the waiting is on the EDT thread
|
static void |
waitForFormName(String name)
Waits for a form change and if no form change occurred after a given timeout then fail the test.
|
static void |
waitForFormName(String name,
long timeout)
Waits for a form change and if no form change occurred after a given timeout then fail the test
|
static void |
waitForFormTitle(String title)
Waits for a form change and if no form change occurred after a given timeout then fail the test.
|
static void |
waitForFormTitle(String title,
long timeout)
Waits for a form change and if no form change occurred after a given timeout then fail the test
|
static void |
waitForUnnamedForm()
Waits for a form change and if no form change occurred after a given timeout then fail the test
|
static void |
waitForUnnamedForm(long timeout)
Waits for a form change and if no form change occurred after a given timeout then fail the test
|
public static void setVerboseMode(boolean v)
v
- true for verbositypublic static void waitFor(int millis)
millis
- the number of milliseconds to waitpublic static Component findByName(String componentName)
componentName
- the name of the component to findpublic static void selectInList(String listName, int offset)
listName
- the name of the list componentoffset
- the offset to selectpublic static void selectInList(int[] path, int offset)
offset
- the offset to selectpublic static Label findLabelText(String text)
text
- the text of the label/buttonpublic static void clickButtonByLabel(String text)
text
- the text on the buttonpublic static void clickButtonByName(String name)
name
- the name of the buttonpublic static void clickButtonByPath(int[] path)
path
- the pathpublic static void goBack()
public static void clickMenuItem(String name)
name
- the name of the commandpublic static Command[] getToolbarCommands()
public static void showSidemenu()
public static void executeToolbarCommandAtOffset(int offset)
getToolbarCommands()
offset
- the offset of the command we want to executepublic static void ensureVisible(Component c)
c
- the componentpublic static void ensureVisible(String componentName)
componentName
- the componentpublic static void ensureVisible(int[] path)
path
- the path to the componentpublic static void waitForFormTitle(String title, long timeout)
title
- the title of the form to wait fortimeout
- Timeout in ms.public static void waitForFormTitle(String title)
title
- the title of the form to wait forpublic static void waitForFormName(String name, long timeout)
name
- the name of the form to wait fortimeout
- Timeout in mspublic static void waitForFormName(String name)
name
- the name of the form to wait forpublic static void waitForUnnamedForm(long timeout)
timeout
- Timeout in milliseconds.public static void waitForUnnamedForm()
public static boolean screenshotTest(String screenshotName)
screenshotName
- the name to use for the storage, must be unique!public static void log(String t)
t
- the string to logpublic static void log(Throwable t)
t
- exception to logpublic static void keyPress(int keyCode)
keyCode
- the keycodepublic static void keyRelease(int keyCode)
keyCode
- the keycodepublic static void gameKeyPress(int gameKey)
gameKey
- the game key (arrows etc.)public static void gameKeyRelease(int gameKey)
gameKey
- the game key (arrows etc.)public static void pointerPress(float x, float y, String componentName)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1componentName
- the name of the componentpublic static void pointerRelease(float x, float y, String componentName)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1componentName
- the name of the componentpublic static void pointerDrag(float x, float y, String componentName)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1componentName
- the name of the componentpublic static void pointerPress(float x, float y, int[] path)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1path
- the path to the componentpublic static void pointerRelease(float x, float y, int[] path)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1path
- the path to the componentpublic static void pointerDrag(float x, float y, int[] path)
x
- the offset within the component as a number between 0 and 1y
- the offset within the component as a number between 0 and 1path
- the path to the componentpublic static Component getComponentByPath(int[] path)
path
- an arraypublic static void setText(String name, String text)
name
- the name of the componenttext
- the text to setpublic static void setText(int[] path, String text)
path
- the path to the componenttext
- the text to setpublic static void assertBool(boolean b)
b
- must be true, otherwise an exception is thrown thus failing the testpublic static void assertBool(boolean b, String errorMessage)
b
- must be true, otherwise an exception is thrown thus failing the testpublic static void fail()
public static void fail(String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertTrue(boolean value)
public static void assertTrue(boolean value, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertFalse(boolean value)
public static void assertFalse(boolean value, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNull(Object object)
public static void assertNull(Object object, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotNull(Object object)
public static void assertNotNull(Object object, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertSame(Object expected, Object actual)
public static void assertSame(Object expected, Object actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotSame(Object expected, Object actual)
public static void assertNotSame(Object expected, Object actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertEqual(byte expected, byte actual)
public static void assertEqual(byte expected, byte actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertEqual(short expected, short actual)
public static void assertEqual(short expected, short actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertEqual(int expected, int actual)
public static void assertEqual(int expected, int actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertEqual(long expected, long actual)
public static void assertEqual(long expected, long actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertEqual(float expected, float actual, double maxRelativeError)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertEqual(float expected, float actual, double maxRelativeError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertEqual(double expected, double actual, double maxRelativeError)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertRange(double expected, double actual, double absoluteError)
expected
- Expected valueactual
- Actual valueabsoluteError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertEqual(double expected, double actual, double maxRelativeError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertRange(double expected, double actual, double maxAbsoluteError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertEqual(Object expected, Object actual)
public static void assertEqual(Object expected, Object actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotEqual(byte expected, byte actual)
public static void assertNotEqual(byte expected, byte actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotEqual(short expected, short actual)
public static void assertNotEqual(short expected, short actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotEqual(int expected, int actual)
public static void assertNotEqual(int expected, int actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertNotEqual(long expected, long actual, double minRelativeError)
public static void assertNotEqual(long expected, long actual, double minRelativeError, String errorMessage)
minRelativeError
- is the minimum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertNotEqual(double expected, double actual, double minRelativeError)
minRelativeError
- is the minimum allowed error, a value of 1 represents a 1% error.public static void assertNotEqual(double expected, double actual, double minRelativeError, String errorMessage)
minRelativeError
- is the minimum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertNotEqual(Object expected, Object actual)
public static void assertNotEqual(Object expected, Object actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertArrayEqual(byte[] expected, byte[] actual)
public static void assertArrayEqual(byte[] expected, byte[] actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertArrayEqual(short[] expected, short[] actual)
public static void assertArrayEqual(short[] expected, short[] actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertArrayEqual(int[] expected, int[] actual)
public static void assertArrayEqual(int[] expected, int[] actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertArrayEqual(long[] expected, long[] actual, double maxRelativeError)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertArrayEqual(long[] expected, long[] actual, double maxRelativeError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertArrayEqual(float[] expected, float[] actual, double maxRelativeError)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertArrayEqual(float[] expected, float[] actual, double maxRelativeError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertArrayEqual(double[] expected, double[] actual, double maxRelativeError)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.public static void assertArrayEqual(double[] expected, double[] actual, double maxRelativeError, String errorMessage)
maxRelativeError
- is the maximum allowed error, a value of 1 represents a 1% error.errorMessage
- is a string describing the failurepublic static void assertArrayEqual(Object[] expected, Object[] actual)
public static void assertArrayEqual(Object[] expected, Object[] actual, String errorMessage)
errorMessage
- is a string describing the failurepublic static void assertException(RuntimeException exception, Runnable expression)
exception
- expression
- public static void assertException(RuntimeException exception, Runnable expression, String errorMessage)
exception
- expression
- errorMessage
- public static void assertNoException(Runnable expression)
expression
- public static void assertNoException(Runnable expression, String errorMessage)
expression
- errorMessage
- public static void assertTitle(String title)
title
- the tile to verifypublic static void assertLabel(String name, String text)
name
- the name of the labeltext
- the text of the labelpublic static void assertLabel(int[] path, String text)
path
- the path of the labeltext
- the text of the labelpublic static void assertLabel(String text)
text
- the text of the labelpublic static void assertTextArea(String name, String text)
name
- the name of the TextAreatext
- the text of the TextAreapublic static void assertTextAreaContaining(String name, String text)
name
- the name of the TextAreatext
- the sequence to search for in the TextAreapublic static void assertTextAreaStartingWith(String name, String text)
name
- the name of the TextAreatext
- the prefix to search for in the TextAreapublic static void assertTextAreaEndingWith(String name, String text)
name
- the name of the TextAreatext
- the suffix to search for in the TextAreapublic static void assertTextArea(int[] path, String text)
path
- the path to the text areatext
- the text of the labelpublic static void assertTextArea(String text)
text
- the text of the label