Created
June 8, 2017 13:13
-
-
Save vyo/76b93765de4a2449d22de809dbae57fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ControllerTest<T> extends JerseyTest { | |
private Class<T> controllerClass; | |
private T controller; | |
private Map<String, Object> args; | |
@Rule | |
public ExpectedException expectedException = ExpectedException.none(); | |
@Override | |
public Application configure() { | |
try { | |
init(); | |
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { | |
System.err.println(e); | |
System.err.println(e.getMessage()); | |
e.printStackTrace(System.err); | |
fail(); | |
} | |
return testResourceConfig(asArray(EchoUserProvider.class, controllerClass), controller); | |
} | |
private void init() | |
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { | |
controllerClass = (Class<T>) | |
((ParameterizedType) getClass().getGenericSuperclass()) | |
.getActualTypeArguments()[0]; | |
Constructor<T> testConstructor = findTestConstructor(controllerClass); | |
Object[] parameters = createMockConstructorParameters(testConstructor); | |
args = createArgumentMap(parameters); | |
controller = testConstructor.newInstance(parameters); | |
} | |
protected T getController() { | |
return controller; | |
} | |
protected Object getField(Class argClass) { | |
return args.get(argClass.getSimpleName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment