java - Mock an attribute within an HttpServlet through the WebApplicationContext -


suppose have httpservlet attribute (myattribute). want replace latter mock, after servlet has been initialized.

i'm instantiating attribute in overridden myservlet.init() method this:

webapplicationcontext wac = getwebapplicationcontext(); this.myattribute = (myattribute) wac.getbean("myattribute"); 

now, in unit test got webapplicationcontext object.1

i planned mocking attribute this:

myservlet myservlet = (myservlet) webapplicationcontext.getservletcontext().getservlet("myservlet"); myservlet.setmyattribute(easymock.createstrictmock(myattribute.class)); 

unfortunately, servletcontext().getservlet() method deprecated, returns null , permanently removed in future versions. hence question:

how mock attribute of httpservlet through webapplicationcontext?

1: due unit test starting tomcat'ish server instance in own thread returning me webapplicationcontext of application after it's , running.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -