Java Reference
In-Depth Information
stocks.add("S1");
stocks.add("S2");
stocks.add("S3");
stockWatcher.refreshWatchList();
Timer timer = new Timer()
{
private void assertStockPrice(FlexTable stocksFlexTable,
int row, String price, String change) {
assertEquals(price, stocksFlexTable.getText(row, 1));
assertEquals(change, stocksFlexTable.getText(row, 2));
}
D
E
F
@Override
public void run()
{
Throwable lastRefreshThrowable =
stockWatcher.getLastRefreshThrowable();
if (lastRefreshThrowable != null) {
this.throwUnchekedException(lastRefreshThrowable);
}
FlexTable stocksFlexTable = stockWatcher.getStocksFlexTable();
assertEquals("Symbol", stocksFlexTable.getText(0, 0));
assertEquals("Price", stocksFlexTable.getText(0, 1));
assertEquals("Change", stocksFlexTable.getText(0, 2));
this.assertStockPrice(stocksFlexTable, 1,
"101.00", "+0.01 (+0.01%)");
this.assertStockPrice(stocksFlexTable, 2,
"102.00", "+0.02 (+0.02%)");
this.assertStockPrice(stocksFlexTable, 3,
"103.00", "+0.03 (+0.03%)");
StockWatcherTest.this.finishTest();
}
G
H
I
J
private void throwUnchekedException(
Throwable lastRefreshThrowable) {
String msg = lastRefreshThrowable.toString();
if (lastRefreshThrowable instanceof StatusCodeException) {
msg = "HTTP status code " + ((StatusCodeException)
lastRefreshThrowable).getStatusCode() + ": " + msg;
}
throw new IllegalStateException(msg, lastRefreshThrowable);
}
};
this.delayTestFinish(5000);
timer.schedule(100);
}
}
A
GWT
test case must extend the
GWT
class
GWTTestCase
b
and implement a method
with the signature
public
String
getModuleName()
to return the name of the module
being tested
C
. We start the test method by instantiating the model class and initializ-
ing it with input data
D
, the three stock symbols
"S1"
,
"S2"
, and
"S3"
. Next, we call
the
refreshWatchList
method in listing 13.14, which performs the asynchronous
RPC
E
.
We need to allow the test method to complete while allowing assertions to run. To
do so, we use a
GWT
Timer
F
to schedule our assertions. Our
Timer
's
run
method
1)
1!