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.params.id = 5
  10. testController.params.max = 45
  11. testController.index();
  12.  
  13.  
  14.  
  15. // Service object
  16.  
  17. class myService {
  18.  
  19.     def myMethod(param, param) {
  20.         // doStuff
  21.     }
  22. }
  23.  
  24. // Controller object
  25. class MyController {
  26.     def myService;
  27.  
  28.     def index = {
  29.         if(myService.myMethod(params.id, params.max)) {
  30.             render('true');
  31.         }else{
  32.             render('false');
  33.         }
  34.     }
  35. }
RAW Paste Data
Top