@Test public void newConnectionSpecInstanceCalledWithTwoArgumentConstructor() { TestConnectionSpecImpl spec = (TestConnectionSpecImpl) factory.newConnectionSpecInstance( TestConnectionSpecImpl.class, new Class<?>[]{int.class, String.class}, new Object[]{4711, "property2"}); assertThat(spec.property1).isEqualTo(4711); assertThat(spec.property2).isEqualTo("property2"); }
protected ConnectionSpec newConnectionSpecInstance(final Class<?> connectionSpecClass, final Class<?>[] constructorParameterTypes, final Object[] constructorArguments) { Object connSpecImpl = null; try { Constructor<?> constructor = connectionSpecClass.getConstructor(constructorParameterTypes); connSpecImpl = constructor.newInstance(constructorArguments); } catch (SecurityException e) { final String msg = "Can not access declared constructor: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (NoSuchMethodException e) { final String msg = "No such constructor: "; return throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (IllegalArgumentException e) { throw new InternalHiberSapException("No such constructor: " + getSignature(connectionSpecClass, constructorArguments), e); } catch (InstantiationException | IllegalAccessException e) { final String msg = "Cannot create new instance of: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (InvocationTargetException e) { final String msg = "Constructor threw an Exception: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } if (!ConnectionSpec.class.isAssignableFrom(connSpecImpl.getClass())) { throw new InternalHiberSapException(connectionSpecClass + " does not implement " + ConnectionSpec.class); } return (ConnectionSpec) connSpecImpl; }
AbstractConnectionSpecFactory implements ConnectionSpecFactory { protected ConnectionSpec newConnectionSpecInstance(final Class<?> connectionSpecClass, final Class<?>[] constructorParameterTypes, final Object[] constructorArguments) { Object connSpecImpl = null; try { Constructor<?> constructor = connectionSpecClass.getConstructor(constructorParameterTypes); connSpecImpl = constructor.newInstance(constructorArguments); } catch (SecurityException e) { final String msg = "Can not access declared constructor: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (NoSuchMethodException e) { final String msg = "No such constructor: "; return throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (IllegalArgumentException e) { throw new InternalHiberSapException("No such constructor: " + getSignature(connectionSpecClass, constructorArguments), e); } catch (InstantiationException | IllegalAccessException e) { final String msg = "Cannot create new instance of: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (InvocationTargetException e) { final String msg = "Constructor threw an Exception: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } if (!ConnectionSpec.class.isAssignableFrom(connSpecImpl.getClass())) { throw new InternalHiberSapException(connectionSpecClass + " does not implement " + ConnectionSpec.class); } return (ConnectionSpec) connSpecImpl; } }
AbstractConnectionSpecFactory implements ConnectionSpecFactory { protected ConnectionSpec newConnectionSpecInstance(final Class<?> connectionSpecClass, final Class<?>[] constructorParameterTypes, final Object[] constructorArguments) { Object connSpecImpl = null; try { Constructor<?> constructor = connectionSpecClass.getConstructor(constructorParameterTypes); connSpecImpl = constructor.newInstance(constructorArguments); } catch (SecurityException e) { final String msg = "Can not access declared constructor: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (NoSuchMethodException e) { final String msg = "No such constructor: "; return throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (IllegalArgumentException e) { throw new InternalHiberSapException("No such constructor: " + getSignature(connectionSpecClass, constructorArguments), e); } catch (InstantiationException | IllegalAccessException e) { final String msg = "Cannot create new instance of: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (InvocationTargetException e) { final String msg = "Constructor threw an Exception: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } if (!ConnectionSpec.class.isAssignableFrom(connSpecImpl.getClass())) { throw new InternalHiberSapException(connectionSpecClass + " does not implement " + ConnectionSpec.class); } return (ConnectionSpec) connSpecImpl; }  }
AbstractConnectionSpecFactory implements ConnectionSpecFactory { protected ConnectionSpec newConnectionSpecInstance(final Class<?> connectionSpecClass, final Class<?>[] constructorParameterTypes, final Object[] constructorArguments) { Object connSpecImpl = null; try { Constructor<?> constructor = connectionSpecClass.getConstructor(constructorParameterTypes); connSpecImpl = constructor.newInstance(constructorArguments); } catch (SecurityException e) { final String msg = "Can not access declared constructor: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (NoSuchMethodException e) { final String msg = "No such constructor: "; return throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (IllegalArgumentException e) { throw new InternalHiberSapException("No such constructor: " + getSignature(connectionSpecClass, constructorArguments), e); } catch (InstantiationException | IllegalAccessException e) { final String msg = "Cannot create new instance of: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (InvocationTargetException e) { final String msg = "Constructor threw an Exception: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } if (!ConnectionSpec.class.isAssignableFrom(connSpecImpl.getClass())) { throw new InternalHiberSapException(connectionSpecClass + " does not implement " + ConnectionSpec.class); } return (ConnectionSpec) connSpecImpl; }   }
AbstractConnectionSpecFactory implements ConnectionSpecFactory { protected ConnectionSpec newConnectionSpecInstance(final Class<?> connectionSpecClass, final Class<?>[] constructorParameterTypes, final Object[] constructorArguments) { Object connSpecImpl = null; try { Constructor<?> constructor = connectionSpecClass.getConstructor(constructorParameterTypes); connSpecImpl = constructor.newInstance(constructorArguments); } catch (SecurityException e) { final String msg = "Can not access declared constructor: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (NoSuchMethodException e) { final String msg = "No such constructor: "; return throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (IllegalArgumentException e) { throw new InternalHiberSapException("No such constructor: " + getSignature(connectionSpecClass, constructorArguments), e); } catch (InstantiationException | IllegalAccessException e) { final String msg = "Cannot create new instance of: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } catch (InvocationTargetException e) { final String msg = "Constructor threw an Exception: "; throwInternalHibersapException(connectionSpecClass, constructorParameterTypes, e, msg); } if (!ConnectionSpec.class.isAssignableFrom(connSpecImpl.getClass())) { throw new InternalHiberSapException(connectionSpecClass + " does not implement " + ConnectionSpec.class); } return (ConnectionSpec) connSpecImpl; }    }