KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > netserve > connection > handlers > DelegatingRequestHandlerTestCase


1 package org.codehaus.spice.netserve.connection.handlers;
2
3 import java.net.Socket JavaDoc;
4
5 import com.mockobjects.dynamic.C;
6 import com.mockobjects.dynamic.Mock;
7 import junit.framework.TestCase;
8 import org.codehaus.spice.netserve.connection.RequestHandler;
9
10 public class DelegatingRequestHandlerTestCase
11    extends TestCase
12 {
13    public void testNullPassedIntoCtor()
14       throws Exception JavaDoc
15    {
16       try
17       {
18          new DelegatingRequestHandler( null );
19       }
20       catch ( final NullPointerException JavaDoc npe )
21       {
22          assertEquals( "npe.getMessage()", "handler", npe.getMessage() );
23          return;
24       }
25    }
26
27    public void testDelegateHandlerInvoked()
28       throws Exception JavaDoc
29    {
30       final Mock mockHandler = new Mock( RequestHandler.class );
31       final Socket JavaDoc socket = new Socket JavaDoc();
32       final Long JavaDoc timeout = new Long JavaDoc( 23 );
33       mockHandler.expect( "handleConnection", C.args( C.eq( socket ) ) );
34       mockHandler.expect( "shutdown", C.args( C.eq( timeout ) ) );
35       final RequestHandler handler = (RequestHandler) mockHandler.proxy();
36       final DelegatingRequestHandler delegatingHandler =
37          new DelegatingRequestHandler( handler );
38
39       delegatingHandler.handleConnection( socket );
40       delegatingHandler.shutdown( 23 );
41    }
42 }
43
Popular Tags