1

単体テストを作成しようとしていますが、Integer.classのMockitoマッチャーを作成する方法がわかりません。

私は次の方法をテストしようとしています:

public List<Integer> getAllParticipatingChallengesByTeamId(int teamId) {
        List<Integer> challengeIds = new ArrayList<Integer>();
        MapSqlParameterSource args = new MapSqlParameterSource();

        args.addValue("teamId", teamId);
        try {
            challengeIds = jdbcTemplate.queryForList(SQL_STRING, args, Integer.class);
        } catch (Exception e) {
            challengeIds = null;
        }

        return challengeIds;
    }

次のようなマッチャーを使用して値を返すために、モックされたjdbcTemplateをスタブします。

    when(mockJdbc.queryForList(anyString(), any(SqlParameterSource.class), any(Integer.class)).thenReturn(integerList);

しかしもちろん、これはクラスではなく、整数に一致します。Class.classなどを試してみましたが、オンラインや自分のやり方で理解できなかったようです。

4

1 に答える 1

3

eq(Integer.class)MockitoのイコリティマッチャーであるUse

于 2012-12-05T00:14:52.377 に答える