I have a EncouragementService.groovy
with following method
class EncouragementService {
def stripePaymentService
def encourageUsers(List<User> users){
if(null != users && users.size()>0){
for(User user : users){
//logic
stripePaymentService.encourage(user)
//
}
}
}
}
To test above code in JAVA universe, using JUnit I would first create two or three users in setup. Pass the list of users to encourageUsers(...)
method and check whatever I want with the result.
How can I achieve the same thing here in grails,
import com.github.jmkgreen.morphia.Datastore;
@TestFor(EncouragementService)
class EncouragementServiceSpec {
def morphiaService = new MorphiaService()
void testEncourageUsers() {
List<User> users = createUsers();
encouragementService.(users)
//
}
def createUsers(){
Datastore datastore = morphiaService.dataStoreInstance()
def user = new User()
user.setName("Prayag Upd")
//
datastore.save(user)
[user]
}
}
I am using spock:0.7
plugins {
test(":spock:0.7") { exclude "spock-grails-support" }
}