匹配器异常的使用无效

发布于 2025-02-07 12:24:37 字数 1635 浏览 3 评论 0原文

我是摩知道的新手,并试图为此编写我的测试用例 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 this
getEmployeePorfilebySsoId(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦慕雪 2025-02-14 12:24:37

只是在这里回答我自己的问题。

此行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 one ecomDao.getEmployeeProfileByssoId("12345);.

Silly mistake was using Mockito.eq() inside the Assertions.assertTrue() condition as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文