@Test public void testAnotherThreadSetsDependency() throws InterruptedException { Runnable r1 = new Runnable() { @Override public void run() { try { D.withDependencies(new LoginInfo("user1"), new Callable<Void>() { @Override public Void call() throws Exception { Thread.sleep(1000); return null; } }); } catch (Exception e) { throw new RuntimeException(e); } } }; Thread thread1 = new Thread(r1); thread1.start(); Thread.sleep(200); assertCannotInjectLoginInfo(); thread1.join(); }
public static <T> T withDependencies(Object dep1, Callable<T> what) throws Exception { return withDependencies(ImmutableList.of(dep1), what); }
D { public static <T> T withDependencies(Object dep1, Callable<T> what) throws Exception { return withDependencies(ImmutableList.of(dep1), what); } }
D { public static <T> T withDependencies(Object dep1, Callable<T> what) throws Exception { return withDependencies(ImmutableList.of(dep1), what); }  }
D { public static <T> T withDependencies(Object dep1, Callable<T> what) throws Exception { return withDependencies(ImmutableList.of(dep1), what); }  static T inject(Class<T> cls, Annotation... qualifiers); static void register(DependencyProvider provider); static void unregister(DependencyProvider provider); static T withDependencies(Object dep1, Callable<T> what); static T withDependencies(Object dep1, Object dep2,
                                         Callable<T> what); static T withDependencies(Object dep1, Object dep2, Object dep3,
                                         Callable<T> what); static T withDependencies(List<Object> deps, Callable<T> what); static Annotation qualifier(Class<? extends Annotation> annotationClass); static QualifiedDependency qualifiedDependency(Object dep, Annotation... qualifiers); static void inRequestContext(final Runnable function); static void inRequestContext(final Map<String, Object> context, final Runnable function); }
D { public static <T> T withDependencies(Object dep1, Callable<T> what) throws Exception { return withDependencies(ImmutableList.of(dep1), what); }  static T inject(Class<T> cls, Annotation... qualifiers); static void register(DependencyProvider provider); static void unregister(DependencyProvider provider); static T withDependencies(Object dep1, Callable<T> what); static T withDependencies(Object dep1, Object dep2,
                                         Callable<T> what); static T withDependencies(Object dep1, Object dep2, Object dep3,
                                         Callable<T> what); static T withDependencies(List<Object> deps, Callable<T> what); static Annotation qualifier(Class<? extends Annotation> annotationClass); static QualifiedDependency qualifiedDependency(Object dep, Annotation... qualifiers); static void inRequestContext(final Runnable function); static void inRequestContext(final Map<String, Object> context, final Runnable function);  }