ClassLoaderBeanFactory implements ExtensibleBeanFactory { public void registerEntity(final String key, final String className, final String representative) throws IllegalArgumentException { if (key != null && key.length() > 0 && className != null && className.length() > 0 && representative != null && representative.length() > 0) { if (this.mappingClasses.containsKey(key)) { throw new IllegalArgumentException("key is already used: [key=" + key + ", className=" + className + "]"); } this.mappingClasses.put(key, className); this.mappingReps.put(key, representative); } else { throw new IllegalArgumentException("all args are mandatory: [key=" + key + ", className=" + className + ", rep=" + representative + "]"); } } ClassLoaderBeanFactory(final ClassLoader classLoader);  ClassLoaderBeanFactory(final ClassLoader classLoader,
                                  final Map<String, String> mappingClasses,
                                  final Map<String, String> mappingEntityRepresentatives); void registerDto(final String key, final String className); void registerEntity(final String key, final String className, final String representative); Class getClazz(final String entityBeanKey); Object get(final String entityBeanKey); void releaseResources();  }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityNullKey() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity(null, EntityClass.class.getCanonicalName(), EntityClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityEmptyKey() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("", EntityClass.class.getCanonicalName(), EntityClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityNullClass() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("myEntity", null, EntityClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityEmptyClass() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("myEntity", "", EntityClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityNullRep() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("myEntity", EntityClass.class.getCanonicalName(), null); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityEmptyRep() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("myEntity", EntityClass.class.getCanonicalName(), ""); }
@Test(expected = IllegalArgumentException.class) public void testRegisterEntityDuplicate() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerEntity("myEntity", EntityClass.class.getCanonicalName(), EntityInterface.class.getCanonicalName()); fb.registerEntity("myEntity", EntityClass.class.getCanonicalName(), EntityInterface.class.getCanonicalName()); }