Skip to content

Instantly share code, notes, and snippets.

@NewGyu
Created February 16, 2015 15:44
Show Gist options
  • Save NewGyu/086cfe18f84d5f0cdbcb to your computer and use it in GitHub Desktop.
Save NewGyu/086cfe18f84d5f0cdbcb to your computer and use it in GitHub Desktop.
@Mocked
private Fuga fuga;
:
:
new Expectations(){{
fuga.getName(); result="ホゲ男";
}}
@Mocked
private PageEntityService pageEntityService;
:
:
new Expectations(){{
pageEntityService.createNewContent(); result=new Page();
}}
@Test
public void test() {
PageCreateAction pageCreator = new PageCreateAction();
Deencapsulation.setField(pageCreator, pageEntityService);
pageCreator.process(site);
new Verifications() {{
List<Page> pages;
pageRepository.save(pages = withCapture());
assertThat(pages.size(), is(0));
}};
}
private PageEntityService pageEntityService = new PageEntityService();
@BeforeClass
public static void beforeClass() {
new MockUp<PageEntityService>() {
@Mock
public Page createNewContent() {
return new Page();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment