Skip to content

Instantly share code, notes, and snippets.

@dehora
Created May 24, 2012 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dehora/2778615 to your computer and use it in GitHub Desktop.
Save dehora/2778615 to your computer and use it in GitHub Desktop.
Set up Scala test for Dropwizard resources
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