Created
February 16, 2015 15:44
-
-
Save NewGyu/086cfe18f84d5f0cdbcb to your computer and use it in GitHub Desktop.
JMockit MockUp ref: http://qiita.com/NewGyu/items/0380fa2a3d7f1d020512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mocked | |
private Fuga fuga; | |
: | |
: | |
new Expectations(){{ | |
fuga.getName(); result="ホゲ男"; | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Mocked | |
private PageEntityService pageEntityService; | |
: | |
: | |
new Expectations(){{ | |
pageEntityService.createNewContent(); result=new Page(); | |
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)); | |
}}; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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