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

  • Home
  • SEARCH
  • 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 6896323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:01:28+00:00 2026-05-27T07:01:28+00:00

This is going to be an easy one, but I cannot find the difference

  • 0

This is going to be an easy one, but I cannot find the difference between them and which one to use, if I have both the lib’s included in my classpath?

  • 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-05-27T07:01:29+00:00Added an answer on May 27, 2026 at 7:01 am

    Hamcrest matcher methods return Matcher<T> and Mockito matchers return T. So, for example: org.hamcrest.Matchers.any(Integer.class) returns an instance of org.hamcrest.Matcher<Integer>, and org.mockito.Matchers.any(Integer.class) returns an instance of Integer.

    That means that you can only use Hamcrest matchers when a Matcher<?> object is expected in the signature – typically, in assertThat calls. When setting up expectations or verifications where you are calling methods of the mock object, you use the Mockito matchers.

    For example (with fully qualified names for clarity):

    @Test
    public void testGetDelegatedBarByIndex() {
        Foo mockFoo = mock(Foo.class);
        // inject our mock
        objectUnderTest.setFoo(mockFoo);
        Bar mockBar = mock(Bar.class);
        when(mockFoo.getBarByIndex(org.mockito.Matchers.any(Integer.class))).
            thenReturn(mockBar);
    
        Bar actualBar = objectUnderTest.getDelegatedBarByIndex(1);
        
        assertThat(actualBar, org.hamcrest.Matchers.any(Bar.class));
        verify(mockFoo).getBarByIndex(org.mockito.Matchers.any(Integer.class));
    }
    

    If you want to use a Hamcrest matcher in a context that requires a Mockito matcher, you can use the org.mockito.Matchers.argThat (or org.mockito.hamcrest.MockitoHamcrest.argThat in Mockito 2). It converts a Hamcrest matcher into a Mockito matcher. So, say you wanted to match a double value with some precision (but not much). In that case, you could do:

    when(mockFoo.getBarByDouble(argThat(is(closeTo(1.0, 0.001))))).
        thenReturn(mockBar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is going to an easy one i think but for the life of
Currently we have 2 databases that we are going to use. One comes from
Ok this one is might not have a straight forward answer but lets see.
another Objective-C one for you, probably pretty obvious but I have been at this
I thought this was going to be easy, but it's turning into quite a
Ok, I'm going to try to explain this one as easy as possible! I'm
This must be an easy one but I'm really at a loss... The following
This is likely going to be an easy answer and I'm just missing something,
This is going to sound like a silly question, but I'm still learning C,
This is going to be the noobist of all noob questions, but what exactly

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.