Java Reference
In-Depth Information
Listing 6.24. GeocoderUnitTest.groovy: tests geocoder even if not online
The test sets up a
Stadium
instance that deliberately has the wrong address. The correct
root of the DOM tree is generated using the string data, and the
demand
property of the
stub is used to return it. By executing the test inside the
use
block, the correct answer is
supplied at the proper moment, and the test succeeds.
The
StubFor
and
MockFor
APIs are far more extensive than what's being shown here.
You can demand that a method returns different preset values each time you call it. You can
verify that the methods are called the proper number of times in the proper order by using