Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exemplo de teste usando specs2 e arquitetura limpa
/**
* https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
* https://vimeo.com/43612849
* https://etorreborre.github.io/specs2/guide/SPECS2-3.7/org.specs2.guide.Matchers.html
*
**/
package com.opportunity.objectives.usecases.user
import com.opportunity.objectives.exceptions.UserInvalidException
import com.opportunity.objectives.model.{Friend, User}
import com.opportunity.objectives.persistence.adapter.user.NewUserPersistenceAdapterMock
import org.specs2.mutable.Specification
class SaveNewFriendsUsecaseSpec extends Specification {
"The save new friends usecase" should {
args(sequential=true)
"Save all new friends" ! usecaseForTest().saveAllNewFriends()
"Try save friends with invalid user" ! usecaseForTest().trySaveFriendsWithInvalidUser()
}
case class usecaseForTest() {
def saveAllNewFriends() = {
val persistenceMock = new NewUserPersistenceAdapterMock()
val usecase = new SaveNewFriendsUsecase(persistenceMock)
val user = User(Map[String,Object]())
val friends = List[Friend]()
val savedUser = usecase.save(user, friends)
val savedFriends = persistenceMock.findAllFriendsOf(savedUser)
savedFriends.size must be equalTo 1
}
def trySaveFriendsWithInvalidUser() = {
val persistenceMock = new NewUserPersistenceAdapterMock()
val usecase = new SaveNewFriendsUsecase(persistenceMock)
val user = User(Map[String,Object]())
val friends = List[Friend]()
usecase.save(user, friends) must throwA[UserInvalidException]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment