Merge pull request #8486 from M-Abdelbaset/BAEL-3652/JMockit_partial_mocking

BAEL-3652/JMockit_partial_mocking
This commit is contained in:
Jonathan Cook 2020-01-09 08:41:56 +01:00 committed by GitHub
commit 1d0db565e0
1 changed files with 16 additions and 13 deletions

View File

@ -130,30 +130,33 @@ public class LoginControllerIntegrationTest {
};
}
@Test
public void partialMocking() {
// use partial mock
final LoginService partialLoginService = new LoginService();
LoginService partialLoginService = new LoginService();
partialLoginService.setLoginDao(loginDao);
loginController.loginService = partialLoginService;
final UserForm userForm = new UserForm();
UserForm userForm = new UserForm();
userForm.username = "foo";
// let service's login use implementation so let's mock DAO call
new Expectations() {{
loginDao.login(userForm);
result = 1;
// no expectation for loginService.login
new Expectations(partialLoginService) {{
// let's mock DAO call
loginDao.login(userForm); result = 1;
// no expectation for login method so that real implementation is used
// mock setCurrentUser call
partialLoginService.setCurrentUser("foo");
}};
String login = loginController.login(userForm);
Assert.assertEquals("OK", login);
// verify mocked call
new FullVerifications(partialLoginService) {
};
new FullVerifications(loginDao) {
};
// verify mocked call
new Verifications() {{
partialLoginService.setCurrentUser("foo");
}};
}
}