Created
May 24, 2012 00:31
-
-
Save dehora/2778615 to your computer and use it in GitHub Desktop.
Set up Scala test for Dropwizard resources
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
package net.amadan.example.account | |
import com.yammer.dropwizard.testing.ResourceTest | |
import org.mockito.Mockito._ | |
import org.mockito.Matchers._ | |
import org.junit.Test | |
import org.hamcrest.MatcherAssert.assertThat | |
import org.hamcrest.Matchers._ | |
import com.codahale.jerkson.ScalaModule | |
class AccountResourceTest extends ResourceTest { | |
var id = "SuperHeroNamedTony" | |
var account = new Account(id) | |
var accountService: AccountService = mock(classOf[AccountService]) | |
@Override | |
def setUpResources() { | |
when(accountService.findByID(anyString())).thenReturn(Option(account)) | |
addResource(new AccountResource(accountService)) | |
// add this or you'll get a 500 for message body writer not found | |
addJacksonModule(new ScalaModule(Thread.currentThread().getContextClassLoader)) | |
} | |
@Test | |
def simpleResourceTest() { | |
val response: Account = client().resource("/account/" + id).get(classOf[Account]) | |
assertThat( | |
"GET request calls Tony's theme", | |
response, | |
is(account) | |
) | |
verify(accountService).findByID(account); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment