Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:56:07+00:00 2026-06-13T10:56:07+00:00

I am creating a custom argument matcher in mockito. Using this example: class IsListOfTwoElements

  • 0

I am creating a custom argument matcher in mockito. Using this example:

class IsListOfTwoElements extends ArgumentMatcher<List> {
    public boolean matches(Object list) {
        return ((List) list).size() == 2;
    }
}

This made me wonder why the type of the parameter list is Object instead of List.
Can the argument passed to the match function be something else? And if so shouldn’t the example check the type of the parameter and return false if it isn’t a List?

To rephrase the question a little:
Does mockito promise to only pas the correct type to the matches function? If so, why doesn’t it use the generic type. And if not why doesn’t the example return false if the wrong type is passed to it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:56:07+00:00Added an answer on June 13, 2026 at 10:56 am

    Because the mockito matchers use Hamcrest matchers, in the javadoc link you provided, you’ll see that it inherits the signature of matches in interface org.hamcrest.Matcher which appear to not be generic in the actual interface.

    If the compiler has made his job correctly you can assume you’ll get the correct type though.

    Note that the ArgumentCaptor approach is now recommanded for complex assertions, where you can use AssertJ (maintained clone of FEST-Assert) for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I'm often creating custom assertion methods for my JUnit tests. eg: public void assertArrays(String[]
How do I develop a working example using this plugin: HTML5 JavaScript Pasting Image
I am creating a custom ostream class which is briefly exposed in the following
I am creating a vector of custom objects and calling assign as follows: class
I'm creating a timestamp in CF8 using a custom function. It's then being passed
I have created a custom content type and using views2 for creating various page-views.
I'm following this tutorial http://codemagento.com/2011/03/creating-custom-magento-reports/ creating the simple report module. I have all the
I'm creating custom forum software for a site I'm building, which includes 2 tables
I am creating custom cell in my iphone aap and I am also adding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.