lundi 29 décembre 2014

Mocked class function being called instead of only being mocked

I am mocking a class in spock and just want to check whether the methods inside the method being tested are getting called or not , I don't want internal methods to run.



class CodeProcessor{
void processMessage(Request request){
//Some implementation
encodeMessage(request)
}
void encodeMessage(Request request){
//Some implementation}
}



def "process code test"(){
given:
CodeProcessor codeProcessor = Mock(CodeProcessor)
Request request = new Request()
request.setId(10)
when:
codeProcessor.processMessage(request)
then:
1 * codeProcessor.encodeMessage(request)
}


In above case i need to check only whether encodeMessage is being called or not. But when i run the above code it runs code inside encodeMessage() also. This is not expected behavious. Can anyone point out where I am going wrong here


Aucun commentaire:

Enregistrer un commentaire