匹配器异常的使用无效
我是摩知道的新手,并试图为此编写我的测试用例 getEmployeeporFileBysSoid(String ssoid)
。
以下是方法
public List<EcommProfile> getEmployeePorfilebySsoId(String ssoId) {
List<EcommProfile> profilelist = null;
try (Sqlsession sqlsession = sqlsessionFactory.openEcomSession()) {
profilelist = sqlsession.selectList("org.mybatis.ecommprofile", ssoId);
} catch (Exception e) {
throw e;
}
}
这是我的测试柜
@Mock
SqlSessionFactory sqlSessionFactory;
@Mock
Sqlsession sqlsession;
@InjectMocks
EcommDaoimpl ecommDao;
@Test
public List<EcommProfile> getEmployeePorfilebySsoIdTestException(String ssoId) {
List<EcommProfile> profilelist = new ArrayList<>();
EcommProfile ecommProfile = new EcommProfile();
ecommProfile.setControlNumber("12345");
profilelist.add(ecommProfile);
Mockito.when(sqlsession.selectList(Mockito.eq("org.mybatis.ecommprofile"), Mockito.eq("12345")))
.thenThrow(ApplicationException.class);
Mockito.when(sqlsessionFactory.openEcommSession()).thenReturn(sqlsession);
Assertions.assertTrue(ApplicationException.class, () -> ecomDao.getEmployeeProfileByssoId(Mockito.eq("12345")));
}
以下是我遇到的错误(出现意外的异常类型)
Expected: com.mycompany.exception.ApplicationException
Actual:org.mockito.exceptions.misusing.InvalidUseofMatcherException```.
PS: Please at least give me the hint or something.
I am very new to mockito and trying to write my test cases for thisgetEmployeePorfilebySsoId(String ssoId)
.
Below is the method
public List<EcommProfile> getEmployeePorfilebySsoId(String ssoId) {
List<EcommProfile> profilelist = null;
try (Sqlsession sqlsession = sqlsessionFactory.openEcomSession()) {
profilelist = sqlsession.selectList("org.mybatis.ecommprofile", ssoId);
} catch (Exception e) {
throw e;
}
}
Here is my Testcase for this method
@Mock
SqlSessionFactory sqlSessionFactory;
@Mock
Sqlsession sqlsession;
@InjectMocks
EcommDaoimpl ecommDao;
@Test
public List<EcommProfile> getEmployeePorfilebySsoIdTestException(String ssoId) {
List<EcommProfile> profilelist = new ArrayList<>();
EcommProfile ecommProfile = new EcommProfile();
ecommProfile.setControlNumber("12345");
profilelist.add(ecommProfile);
Mockito.when(sqlsession.selectList(Mockito.eq("org.mybatis.ecommprofile"), Mockito.eq("12345")))
.thenThrow(ApplicationException.class);
Mockito.when(sqlsessionFactory.openEcommSession()).thenReturn(sqlsession);
Assertions.assertTrue(ApplicationException.class, () -> ecomDao.getEmployeeProfileByssoId(Mockito.eq("12345")));
}
Below is the error i am getting (Unexpected exception type thrown)
Expected: com.mycompany.exception.ApplicationException
Actual:org.mockito.exceptions.misusing.InvalidUseofMatcherException```.
PS: Please at least give me the hint or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是在这里回答我自己的问题。
此行
ecomdao.getEmployeeprofilebyssoid(Mockito.eq(“ 12345)
被替换为此ecomdao.getEmployeprofilebyssoid(“ 12345);
。愚蠢的错误是使用
mockito。 eq()
在servertions.asserttrue()
条件中。Just answering my own question here.
This line
ecomDao.getEmployeeProfileByssoId(Mockito.eq("12345)
is replace to this oneecomDao.getEmployeeProfileByssoId("12345);
.Silly mistake was using
Mockito.eq()
inside theAssertions.assertTrue()
condition as well.