I am trying to test some methods within a Domain object, the code seems to execute (based on log) but the assertions fail. I assume I am doing something wrong in the mocking. I am including a simplified version of my code. Based on the log output, the assertion should pass.
class EventDate{
Date start
Date end
}
class Appointments {
hasMany = [ eventDates: EventDate]
def extendDates(start,end){
//some logic on eventDates...
if(create_new) EventDate(start,end).save(flush:true);
}
}
import org.junit.*
import grails.test.mixin.*
@TestFor(Appointments)
@Mock([EventDate,Appointments])
class AppointmentsTests {
def testDomain
void setUp(){
testDomain = new Appointments()
mockDomain(Appointments, [testDomain])
}
void testCoreExtend(){
//Log indicates the correct execution and creation of event
testDomain.extendDates(new Date(),null)
//following returns NullPointerException
assertTrue testDomain.eventDates.size() == 1
}
}
Aucun commentaire:
Enregistrer un commentaire