BindInfoContainer extends AbstractContainer implements Observer { public <T> DefaultBindInfoProviderAdapter<T> createInfoAdapter(Class<T> bindType, ApiBinder apiBinder) { if (this.isInit()) { throw new IllegalStateException("container has been started."); } DefaultBindInfoProviderAdapter<T> adapter = new DefaultBindInfoProviderAdapter<>(bindType); adapter.addObserver(this); adapter.setBindID(adapter.getBindID()); this.spiCallerContainer.notifySpiWithoutResult(BindInfoProvisionListener.class, listener -> { listener.newBindInfo(adapter); }); return adapter; } BindInfoContainer(SpiCallerContainer spiCallerContainer); BindInfo<T> findBindInfo(String infoID); List<BindInfo<T>> findBindInfoList(final Class<T> bindType); BindInfo<T> findBindInfo(final String withName, final Class<T> bindType); Collection<String> getBindInfoIDs(); DefaultBindInfoProviderAdapter<T> createInfoAdapter(Class<T> bindType, ApiBinder apiBinder); @Override synchronized void update(Observable o, Object arg); void forEach(Consumer<BindInfo<?>> action);  }
@Test public void infoTest5() { SpiCallerContainer spiCallerContainer = new SpiCallerContainer(); BindInfoContainer infoContainer = new BindInfoContainer(spiCallerContainer); infoContainer.createInfoAdapter(PojoBean.class, null); infoContainer.init(); try { infoContainer.createInfoAdapter(PojoBean.class, null); assert false; } catch (Exception e) { assert e.getMessage().equals("container has been started."); } infoContainer.close(); }
@Test public void infoTest6() { SpiCallerContainer spiCallerContainer = new SpiCallerContainer(); BindInfoContainer infoContainer = new BindInfoContainer(spiCallerContainer); infoContainer.createInfoAdapter(PojoBean.class, null); infoContainer.createInfoAdapter(PojoBean.class, null); try { infoContainer.init(); assert false; } catch (Exception e) { assert e.getMessage().equals("conflict type '" + PojoBean.class.getName() + "' of same name ''"); } }
@Test public void infoConflictTest1() { SpiCallerContainer spiCallerContainer = new SpiCallerContainer(); BindInfoContainer infoContainer = new BindInfoContainer(spiCallerContainer); infoContainer.createInfoAdapter(PojoBean.class, null).setBindName("abc_1"); try { infoContainer.createInfoAdapter(PojoBean.class, null).setBindName("abc_1"); assert false; } catch (Exception e) { assert e.getMessage().startsWith("duplicate bind -> bindName '"); } }
@Test public void infoConflictTest2() { SpiCallerContainer spiCallerContainer = new SpiCallerContainer(); BindInfoContainer infoContainer = new BindInfoContainer(spiCallerContainer); infoContainer.createInfoAdapter(PojoBean.class, null).setBindID("abc_1"); try { infoContainer.createInfoAdapter(PojoBean.class, null).setBindID("abc_1"); assert false; } catch (Exception e) { assert e.getMessage().startsWith("duplicate bind -> id value is "); } }
@Test public void infoConflictTest3() { SpiCallerContainer spiCallerContainer = new SpiCallerContainer(); BindInfoContainer infoContainer = new BindInfoContainer(spiCallerContainer); try { infoContainer.createInfoAdapter(PojoBean.class, null).setBindType(PojoBean.class); assert true; } catch (Exception e) { assert false; } try { DefaultBindInfoProviderAdapter<SampleFace> adapter = infoContainer.createInfoAdapter(SampleFace.class, null); Method writeMethod = BeanUtils.getWriteMethod("bindType", DefaultBindInfoProviderAdapter.class); writeMethod.invoke(adapter, SampleBean.class); assert false; } catch (Exception e) { if (e instanceof InvocationTargetException == false) { e.printStackTrace(); assert false; } assert ((InvocationTargetException) e).getTargetException().getMessage().equals("'bindType' are not allowed to be changed"); } }