Skip to content

Instantly share code, notes, and snippets.

View vyo's full-sized avatar
💜
Pony/JS/Lua

Manu Weidmann vyo

💜
Pony/JS/Lua
View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sevenp.blog</groupId>
<artifactId>automagic</artifactId>
<version>0.1.0</version>
<dependencies>
public class Util {
/**
* Creates a custom ResourceConfig for use in Jersey Tests.
*
* Registers all resource/class definitions to be used in this test configuration.
*
* Optionally binds specifically configured instances to those definitions, e.g. mocks.
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 class EchoControllerTest extends ControllerTest<EchoController> {
private EchoService echoService;
@Before
public void setup() {
echoService = (EchoService) getField(EchoService.class);
when(echoService.reverse(eq("input"))).thenReturn("tupni");
}
@Test
@GET
public Echo userEcho(@User EchoUser user) {
// ...
return echo;
}
@Override
protected Application configure() {
setup();
ResourceConfig resourceConfig = new ResourceConfig(EchoController.class);
resourceConfig.register(new AbstractBinder() {
protected void configure() {
bind(echoController).to(EchoController.class);
}
});
private EchoController echoController;
// ...
@Before
public void setup() {
initMocks(this);
when(echoService.reverse(eq("input"))).thenReturn("tupni");
echoController = new EchoController(echoService);
}
@Mock
private EchoService echoService;
// ...
initMocks(this);
when(echoService.reverse(eq("input"))).thenReturn("tupni");
public class EchoControllerJerseyTest extends JerseyTest {
@Override
protected Application configure() {
return new ResourceConfig(EchoController.class);
}
@Test
public void echo() throws Exception {
String input = "input";
public class EchoControllerTest {
private EchoController echoController;
@Before
public void init() {
echoController = new EchoController();
}
@Test