Return-Path: list-help: list-unsubscribe: List-Post: List-Id: Mailing-List: contact cactus-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list cactus-user@jakarta.apache.org Received: (qmail 81206 invoked from network); 18 Nov 2003 00:54:32 -0000 Received: from unknown (HELO cerberus.uk.clara.net) (195.8.69.103) by daedalus.apache.org with SMTP; 18 Nov 2003 00:54:32 -0000 Received: from du-037-0077.access.clara.net ([217.158.29.77] helo=tackline.demon.co.uk) by cerberus.uk.clara.net with esmtp (Exim 4.22) id 1ALu8c-0001mV-Dq for cactus-user@jakarta.apache.org; Tue, 18 Nov 2003 00:54:38 +0000 Message-ID: <3FB96C04.9070108@tackline.demon.co.uk> Date: Tue, 18 Nov 2003 00:47:00 +0000 From: Thomas Hawtin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20030225 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Cactus Users List Subject: Re: invoking a private method of a servlet References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Ajay Kumar wrote: > > I have a controller servlet with many private methods and want to write > a testcase for these methods. I tried using reflection for invoking > these methods, but got the following report: Using JUnit, I've always found it easier to refactor so that the Servlet, in this case, delegates to a class with the bulk of the functionality. JUnit uses exactly the same interface (in the general sense) as the Servlet and everyone is happy. In any case it's probably not a bad idea to arrange for classes that extend other groups' code to be as small and simple as possible. > type="org.apache.cactus.client.ServletExceptionWrapper"> > java.lang.reflect.InvocationTargetException > [...] > Caused by: java.lang.NullPointerException > at > com.appnetix.mainprospecting.control.MainServlet.getEmailTemplates(MainServlet.java:226) That looks like your servlet throwing the NPE. Perhaps it's not initialised? Method.invoke will itself throw an NPE if you try to call a non-static method with a null target, althugh it doesn't look like the case in this instance. w.r.t security/accessibility, for private methods you should usually call setAccessible(true) which is defined in Method's superclass, otherwise an IllegalAccessException will be thrown. As ever you will need suitably lax security, but Cactus requires that to be wide open anyway. Tom Hawtin