### Question:
InjectorImpl implements Serializable, Injector { @Override public <T> T inject(final T instance) { if (instance == null) { return null; } doInject(instance.getClass(), unwrap(instance)); return instance; }  @Override T inject(final T instance);  }### Answer:
@Test void configurationInjection() { final Supplier<MyConfig> config = injector.inject(new InjectedConfig()).config; assertNotNull(config); final MyConfig configuration = config.get(); assertEquals("ok", configuration.getValue()); }
@Test void inject() { final Injected instance = new Injected(); injector.inject(instance); assertNotNull(instance.cache); assertNotNull(instance.caches); assertEquals(2, instance.caches.size()); }
@Test void injectWithProxy() throws Exception { final Map<Class<?>, Object> services = new HashMap<>(1); LocalCache localCache = new LocalCacheService("LocalCacheServiceTest", System::currentTimeMillis, this.executor); services.put(LocalCache.class, localCache); final InjectedCache instance = new InjectedCache(); ProxyGenerator proxyGenerator = new ProxyGenerator(); final Class<?> proxyClass = proxyGenerator .generateProxy(Thread.currentThread().getContextClassLoader(), InjectedCache.class, "injector", InjectedCache.class.getName()); final InjectedCache proxy = InjectedCache.class.cast(proxyClass.getConstructor().newInstance()); proxyGenerator.initialize(proxy, new InterceptorHandlerFacade(instance, services)); injector.inject(proxy); assertEquals("false", proxy.getString()); assertTrue(proxy.getClass().getName().endsWith("$TalendServiceProxy")); }
@Test void invalidConfigurationInjectionSupplier() { assertThrows(IllegalArgumentException.class, () -> injector.inject(new InvalidInjectedConfig1())); }
@Test void invalidConfigurationInjectionDirectConfig() { assertThrows(IllegalArgumentException.class, () -> injector.inject(new InvalidInjectedConfig2())); }