Well, I found one way, though I would certainly
welcome others' solutions.
Using NamingManager.setInitialContextFactoryBuilder()
as follows:
private Mock setupTestJNDI() throws NamingException
{
final Mock mock = new Mock(Context.class);
NamingManager.setInitialContextFactoryBuilder(new
InitialContextFactoryBuilder()
{
public InitialContextFactory
createInitialContextFactory(Hashtable
environment) throws NamingException
{
TestFactory.context = (Context)mock.proxy();
TestFactory factory = new TestFactory();
return factory;
}
});
return mock;
}
--- Joel Shellman <joe...@ya...> wrote:
> How are people testing JNDI lookups and such? I see
> a
> MockContext class in the mockobjects library, but
> nothing about MockInitialContextFactory.
>
> Ie. if a class calls new InitialContext() what do
> you
> do to test it by controlling what it recieves?
>
> I tried to write a quick and dirty mock for
> InitialContextFactory but ran into trouble because
> it's loaded in a different class loader. So even
> setting a static variable on the class did not work.
>
> So I'm wondering what other people are doing to test
> this?
>
> -joel
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product
> search
> http://shopping.yahoo.com
>
>
>
-------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Mockobjects-java-users mailing list
> Moc...@li...
>
https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
|