Java Reference
In-Depth Information
Figure 6.3
Testing the
JettySample
class in a browser
6.3
Stubbing the web server's resources
You now know how to easily start and configure Jetty, so let's focus on the
HTTP
con-
nection unit test. You'll write a first test that verifies you can call a valid
URL
and get
its content.
6.3.1
Setting up the first stub test
To verify that the
WebClient
works with a valid
URL
, you need to start the Jetty server
before the test, which you can implement in a test case
setUp
method. You can also
stop the server in a
tearDown
method. Listing 6.3 shows the code.
Listing 6.3
First test to verify that
WebClient
works with a valid URL
[...]
import
java.net.URL;
import
org.junit.test;
import
org.junit.Before;
import
org.junit.After;
public
class
TestWebClientSkeleton {
@Before
public
void
setUp() {
}