
org.jnario.runner.internal.ExampleGroupRunnerBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.jnario.standalone Show documentation
Show all versions of org.jnario.standalone Show documentation
The required libraries to execute Jnario specifications without Eclipse.
The newest version!
/*******************************************************************************
* Copyright (c) 2012 BMW Car IT and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.jnario.runner.internal;
import java.lang.reflect.Method;
import java.util.Set;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.jnario.runner.ExampleGroupRunner;
import org.jnario.runner.NameProvider;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runners.model.InitializationError;
public class ExampleGroupRunnerBuilder {
private final Class> declaredClass;
private final NameProvider nameProvider;
private Set setups;
public ExampleGroupRunnerBuilder(Class> declaredClass,
NameProvider nameProvider, Set setups) {
this.declaredClass = declaredClass;
this.nameProvider = nameProvider;
this.setups = setups;
}
public Runner build() throws InitializationError {
RunWith runWith = declaredClass.getAnnotation(RunWith.class);
if (runWith == null) {
return new ExampleGroupRunner(declaredClass, nameProvider, setups);
} else {
try {
Class> runnerType = runWith.value();
try {
return (Runner) runnerType.getConstructor(Class.class,
NameProvider.class, Set.class).newInstance(
new Object[] { declaredClass, nameProvider, setups});
} catch (NoSuchMethodException e) {
try {
return (Runner) runnerType.getConstructor(Class.class)
.newInstance(new Object[] { declaredClass });
} catch (NoSuchMethodException e2) {
throw new InitializationError("Could not instantiate "
+ runnerType.getName());
}
}
} catch (Exception e) {
Exceptions.sneakyThrow(e);
return null; // not reachable
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy