jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Raible" <m...@raibledesigns.com>
Subject RE: Testing Listeners
Date Thu, 18 Sep 2003 15:46:11 GMT
That worked - thanks.

Matt

-----Original Message-----
From: Vincent Massol [mailto:vmassol@pivolis.com] 
Sent: Thursday, September 18, 2003 12:12 AM
To: 'Cactus Users List'
Subject: RE: Testing Listeners


I've never used ServletContextListener but I've had a quick look and it
looks easy to unit test. Let's take an example:

public class MyListener implements ServletContextListener
{
    public void contextDestroyed(ServletContextEvent sce)
    {
      [...]
    }
    public void contextInitialized(ServletContextEvent sce)
    {
      [...]
    }
}

Here's the test:

public class MyListenerTest extends ServletTestCase
{
    public void testXXX()
    {
        // setup
        ServletContextEvent sce = 
            new ServletContextEvent(config.getServletContext());
        MyListener listener = new MyListener();
        
        // test
        listener.contextInitialized(sce);

        // asserts
   }
}

Now, what I don't know is whether you need the ServletContext in a given
state or not?

Is that the kind of test you want?

-Vincent


> -----Original Message-----
> From: Matt Raible [mailto:matt@raibledesigns.com]
> Sent: 18 September 2003 04:22
> To: 'Cactus Users List'
> Subject: Testing Listeners
> 
> What is the recommended way to test Listeners with Cactus.  I have a 
> StartupListener ...
> 
> public class StartupListener implements ServletContextListener
> 
> ... That talks to a database and reads a number of properties files - 
> and stuffs objects into the servlet context.  I basically just need to

> verify that the variables get set correctly.
> 
> Thanks,
> 
> Matt
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org



Mime
View raw message