Skip to content

Instantly share code, notes, and snippets.

@yamanyar
Created April 7, 2012 05:15
Show Gist options
  • Save yamanyar/2325479 to your computer and use it in GitHub Desktop.
Save yamanyar/2325479 to your computer and use it in GitHub Desktop.
capture parameters example
//... lines of codes... templateService is mocked...
//here is regular expectation; we know the parameter that will be passed and we are verifying it
expect(nodeService.getProperties(fakeChildNodeRef2)).andReturn(new HashMap());
//create a capturer; which will capture a map item
Capture<Map> capturer = new Capture<Map>();
//write your expectaion again; this time we want to have a reference to whatever passed to
//our method processTemplate in mocked item templateService
expect(templateService.processTemplate(isA(String.class), and(isA(Map.class), capture(capturer)))).andReturn("fake");
//replay; let the action begin
replay(nodeService, templateService);
String fake = testMe.serializeNode(fakeNodeRef);
//verify that our methods were called according to our expectations
verify(nodeService, templateService);
//now, let get the object from capturer to verify it..
String outputGenerated = (String) (capturer.getValue()).get("json");
//..lines of codes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment