You have to create the injector @BeforeClass gets called, and you need to use requestStaticInjection in you modules for the classes in which you want to inject statics. But if you're trying to unit test with Guice, you could also have a look at one of the projects that help you with that, like GuiceBerry or AtUnit.
Hope this helps, Robbie On Tue, Oct 28, 2008 at 4:46 PM, Andrew Clegg <[EMAIL PROTECTED]>wrote: > > PS This is using old-skool Guice 1.0 release, I'm hesitant to upgrade > while I'm still learning, but if this is a known issue then I can... > > Cheers. > > Andrew. > > 2008/10/28 Andrew Clegg <[EMAIL PROTECTED]>: > > Maybe I'm doing something stupid, but what's wrong with this picture: > > > > > > // In my module RealServicesModule > > > > bind( String.class ).annotatedWith( > > FuncNetVersionDependent.class ).toInstance( > > "http://cathdb.info/FuncNet_0_1/" ); > > > > > > // A static member in my test class > > > > @Inject @FuncNetVersionDependent > > private static String __namespace; > > > > // Shortly afterwards, in a static method (a JUnit @BeforeClass method) > > > > __namespace = Guice.createInjector( new RealServicesModule() > > ).getInstance( String.class ); > > assertNotNull( __namespace ); > > System.err.println( "'" + __namespace + "'" ); > > > > > > When I run this, I get '' -- i.e. __namespace is an empty string! Huh? > > > > __namespace isn't referenced anywhere else in my test class, and > > that's currently the only bind command in my module... > > > > Any suggestions? > > > > Andrew. > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~----------~----~----~----~------~----~------~--~---
