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
| class ClassThatReturnsFutures() { | |
| def goDoSomething() : Future[String] = { | |
| future { | |
| println("I best do this asynchronously") | |
| "The result" | |
| } | |
| } | |
| } |
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
| test("Test a asynchronous method synchronously") { | |
| val underTest = new ClassThatReturnsFutures() | |
| val futureResult = underTest.goDoSomething() | |
| futureResult onComplete { | |
| case Success(value) => value should equal("Something") | |
| case Failure(exp) => fail(exp) | |
| } | |
| } |
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
| test("Test a asynchronous method synchronously - whenReady") { | |
| val underTest = new ClassThatReturnsFutures() | |
| val futureResult = underTest.goDoSomething() | |
| whenReady(futureResult) { result => | |
| result should equal("The result") | |
| } | |
| } |
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
| test("Test a asynchronous method synchronously - futureResult") { | |
| val underTest = new ClassThatReturnsFutures() | |
| val futureResult = underTest.goDoSomething() | |
| futureResult.futureValue should equal("The result") | |
| } |
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
| class ChildActor extends Actor { | |
| def receive: Actor.Receive = { | |
| case "Do something" => { | |
| // Do something important | |
| context.parent ! "I was told to do something and I did it" | |
| } | |
| } | |
| } |
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
| class ChildActorTest extends TestKit(ActorSystem("ChildActorTest")) with FunSuiteLike with ShouldMatchers { | |
| test("Should inform parent when told to do something") { | |
| val parent = TestProbe() | |
| val underTest = TestActorRef(Props[ChildActor], parent.ref, "ChildActor") | |
| underTest ! "Do something" | |
| parent.expectMsg("I was told to do something and I did it") | |
| } | |
| } |
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
| @Controller | |
| public class ExampleWebAppController { | |
| @RequestMapping("/exampleendpoint") | |
| public @ResponseBody Payload exampleEndpoint(@RequestParam(value="input") String input) { | |
| return new Payload("Something really important: " + input); | |
| } | |
| } |
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
| class ExampleWebAppSpecification extends Specification { | |
| def "Should return 200 & a message with the input appended"() { | |
| setup: | |
| def primerEndpoint = new RESTClient( 'http://localhost:8080/' ) | |
| when: | |
| def resp = primerEndpoint.get([ path: 'exampleendpoint', query : [ input : 'Get a hair cut' ]]) | |
| then: | |
| with(resp) { | |
| status == 200 | |
| contentType == "application/json" |
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
| apply plugin: 'spring-boot' | |
| apply plugin: 'java' | |
| apply plugin: 'groovy' |
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
| compile("org.codehaus.groovy:groovy-all:2.2.0") | |
| compile("com.fasterxml.jackson.core:jackson-databind") | |
| testCompile("org.spockframework:spock-core:0.7-groovy-2.0") | |
| testCompile("org.codehaus.groovy.modules.http-builder:http-builder:0.7+") | |
| testCompile("net.sf.json-lib:json-lib:2.4+") |