This file contains 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
<?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> |
This file contains 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 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. |
This file contains 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 |
This file contains 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 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 |
This file contains 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
@GET | |
public Echo userEcho(@User EchoUser user) { | |
// ... | |
return echo; | |
} |
This file contains 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
@Override | |
protected Application configure() { | |
setup(); | |
ResourceConfig resourceConfig = new ResourceConfig(EchoController.class); | |
resourceConfig.register(new AbstractBinder() { | |
protected void configure() { | |
bind(echoController).to(EchoController.class); | |
} | |
}); |
This file contains 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
private EchoController echoController; | |
// ... | |
@Before | |
public void setup() { | |
initMocks(this); | |
when(echoService.reverse(eq("input"))).thenReturn("tupni"); | |
echoController = new EchoController(echoService); | |
} |
This file contains 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
@Mock | |
private EchoService echoService; | |
// ... | |
initMocks(this); | |
when(echoService.reverse(eq("input"))).thenReturn("tupni"); |
This file contains 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 class EchoControllerJerseyTest extends JerseyTest { | |
@Override | |
protected Application configure() { | |
return new ResourceConfig(EchoController.class); | |
} | |
@Test | |
public void echo() throws Exception { | |
String input = "input"; |
This file contains 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 class EchoControllerTest { | |
private EchoController echoController; | |
@Before | |
public void init() { | |
echoController = new EchoController(); | |
} | |
@Test |