private Fixture selectFixture(String[] fixtureAndParameters) throws Throwable { List<String> values = toList(fixtureAndParameters); String name = CollectionUtil.shift(values); return systemUnderDevelopment.getFixture(name, values.toArray(new String[values.size()])); } }
@Override public Object convert(String value) throws IllegalArgumentException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { List<String> parameters = toList(ClassUtils.escapeValues(value.split(";"))); Class< ? > klass = ClassUtils.loadClass(shift(parameters)); if (expectedType != null && ! expectedType.isAssignableFrom(klass)) { throw new IllegalArgumentException("Class " + expectedType.getName() + " is not assignable from" + klass .getName()); } if (parameters.size() == 0) { return klass.newInstance(); } String[] args = parameters.toArray(new String[parameters.size()]); Constructor< ? > constructor = klass.getConstructor(args.getClass()); return constructor.newInstance(new Object[] { args }); } }
public static <C> C createInstanceFromClassNameWithArguments(ClassLoader classLoader, String classWithArguments, Class<C> expectedType) throws UndeclaredThrowableException { try { List<String> parameters = toList(escapeValues(classWithArguments.split(";"))); Class< ? > klass = ClassUtils.loadClass(classLoader, shift(parameters)); if ( ! expectedType.isAssignableFrom(klass)) { throw new IllegalArgumentException("Class " + expectedType.getName() + " is not assignable from " + klass .getName()); } if (parameters.size() == 0) { return expectedType.cast(klass.newInstance()); } String[] args = parameters.toArray(new String[parameters.size()]); Constructor< ? > constructor = klass.getConstructor(args.getClass()); return expectedType.cast(constructor.newInstance(new Object[] { args })); } catch (ClassNotFoundException e) { throw new UndeclaredThrowableException(e); } catch (InstantiationException e) { throw new UndeclaredThrowableException(e); } catch (IllegalAccessException e) { throw new UndeclaredThrowableException(e); } catch (NoSuchMethodException e) { throw new UndeclaredThrowableException(e); } catch (InvocationTargetException e) { throw new UndeclaredThrowableException(e); } }
@Override public void parse(CommandLine cli, String[] args) throws InvalidOptionException, WrongOptionUsageException { List<String> tokens = CollectionUtil.toList(args); while ( ! tokens.isEmpty()) { String token = CollectionUtil.shift(tokens); if (Pattern.compile("(--.+)").matcher(token).lookingAt()) { cli.getOptionWithLongForm(token).consume(tokens); } else if (Pattern.compile("(-.)").matcher(token).lookingAt()) { cli.getOptionWithShortForm(token).consume(tokens); } else { cli.addArgument(token); } } } }
@Override public void specificationDone(Example spec, Statistics statistics) { try { String[] args1 = args(definitionRef); URI location = URI.create(URIUtil.raw(definitionRef.get(1))); List<Serializable> args = CollectionUtil.toList(args1[1], args1[2], (ArrayList<String>) CollectionUtil .toList(location.getFragment(), definitionRef.get(4), sut, XmlReport.toXml(documentRef))); String msg = getRestClient().saveExecutionResult(args); if (!("<success>".equals(msg))) { throw new IllegalStateException(msg); } } catch (LivingDocServerException e) { // Old server / incompatible method ? if (e.getMessage().indexOf(NoSuchMethodException.class.getName()) == -1) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } catch (IllegalStateException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } catch (IOException e) { // @todo : Log ? Critical ? Do we want the test execution to // fail if we can't post the result back ? throw ExceptionImposter.imposterize(e); } } }