Last active
December 16, 2017 17:34
-
-
Save need4spd/5712838 to your computer and use it in GitHub Desktop.
Mockito
This file contains hidden or 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
| //Dao class | |
| public class DAO { | |
| public Result select(Param param) { | |
| return sqlClient.select("id", param); | |
| } | |
| } |
This file contains hidden or 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
| //Paramter class | |
| public class Param { | |
| private String name; | |
| public void setName(String name) { | |
| this.name = name; | |
| } | |
| public String getName() { | |
| return name; | |
| } | |
| } |
This file contains hidden or 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
| //Service | |
| public class Service { | |
| @Autowired | |
| private DAO dao; | |
| public Result select() { | |
| Param param = new Param(); | |
| return dao.select(param); | |
| } | |
| } |
This file contains hidden or 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
| //TestCase | |
| @Mock | |
| private DAO dao; | |
| @InjectMocks | |
| private Service service; | |
| @Test | |
| public void test() { | |
| when(dao.select(new Param())).thenReturn(new Result()); | |
| service.select(); | |
| Assert.assertTrue(true); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment