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
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
@Mock
EchoUserProvider echoUserProviderMock;
@Override
protected Application configure() {
setup();
ResourceConfig resourceConfig = new ResourceConfig(
EchoController.class,
EchoUserProvider.class);
@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
@Path("echo")
public class EchoController {
private EchoService echoService;
/**
* explicit default constructor;
* required by Jersey
*/
public EchoController() {