SHARE
TWEET

Untitled

a guest Aug 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Unit test
  2.  
  3. def mockService = mockFor(MyService)
  4.  
  5. mockService.demand.myMethod { param, param -> return true; }
  6.  
  7. testController.myService = mockService.createMock();
  8.  
  9. testController.index([id:5,max;45]);
  10.  
  11.  
  12.  
  13. // Service object
  14.  
  15. class myService {
  16.  
  17.     def myMethod(param, param) {
  18.         // doStuff
  19.     }
  20. }
  21.  
  22. // Controller object
  23. class MyController {
  24.     def myService;
  25.  
  26.     def index = {
  27.         if(myService.myMethod(params.id, params.max)) {
  28.             render('true');
  29.         }else{
  30.             render('false');
  31.         }
  32.     }
  33. }
RAW Paste Data
Top