### Question:
SingletonPool { @SuppressWarnings("unchecked") public static <I, T extends I> T get(Class<I> clazz, IFactory factory) throws Exception { if (clazz == null) { return null; } if (factory == null) { factory = RouterComponents.getDefaultFactory(); } Object instance = getInstance(clazz, factory); Debugger.i("[SingletonPool] get instance of class = %s, result = %s", clazz, instance); return (T) instance; }  @SuppressWarnings("unchecked") static T get(Class<I> clazz, IFactory factory);  }### Answer:
@Test public void get() throws Exception { TestSingleton o1 = SingletonPool.get(TestSingleton.class, null); Assert.assertNotNull(o1); TestSingleton o2 = SingletonPool.get(TestSingleton.class, null); Assert.assertSame(o1, o2); }
@Test public void provider() throws Exception { TestProvider p = SingletonPool.get(TestProvider.class, null); Assert.assertNotNull(p); Assert.assertEquals("provider", p.getName()); }
@Test public void factory() throws Exception { TestFactory o = SingletonPool.get(TestFactory.class, new IFactory() { @NonNull @Override public <T> T create(@NonNull Class<T> clazz) throws Exception { return clazz.getConstructor(String.class).newInstance("factory"); } }); Assert.assertNotNull(o); Assert.assertEquals("factory", o.getName()); }