initial-context

How to fake InitialContext with default constructor

时间秒杀一切 提交于 2019-12-03 09:00:46
问题 All, I'm trying to do some unit testing in some archaic java code (no interfaces, no abstraction, etc.) This is a servlet that uses a ServletContext (which I'm assuming is set up by Tomcat) and it has database information is set up in the web.xml/context.xml file. Now, I've figured out how to make a Fake ServletContext, but the code has InitialContext _ic = new InitialContext(); all over the place (so it isn't feasible to replace it). I need to find a way to make a default InitialContext()

How to fake InitialContext with default constructor

爷,独闯天下 提交于 2019-12-02 23:07:52
All, I'm trying to do some unit testing in some archaic java code (no interfaces, no abstraction, etc.) This is a servlet that uses a ServletContext (which I'm assuming is set up by Tomcat) and it has database information is set up in the web.xml/context.xml file. Now, I've figured out how to make a Fake ServletContext, but the code has InitialContext _ic = new InitialContext(); all over the place (so it isn't feasible to replace it). I need to find a way to make a default InitialContext() able to do the _ic.lookup(val) without throwing an exception. I'm assuming there is some way that the