Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>b</code> is a mock, so you shouldn't need to inject anything. After all it isn't executing any real methods (unless you explicitly do so with by calling <a href="http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#16" rel="nofollow"><code>thenCallRealMethod</code></a>), so there is no need to inject any implementation of <code>ClassANeededByClassB</code>.</p> <p>If <code>ClassB</code> is the class under test or a spy, then you need to use the <a href="http://docs.mockito.googlecode.com/hg/org/mockito/InjectMocks.html" rel="nofollow"><code>@InjectMocks</code></a> annotation which will inject any matching mocks into <code>ClassB</code>.</p> <pre><code>@RunWith(MockitoJUnitRunner.class) public class ConstraintBuilderTest { @Mock ClassANeededByClassB a; @InjectMocks ClassB b; // ... } </code></pre> <hr> <p>As you said, Mockito doesn't support mocking <code>equals</code>. There might be some workarounds but I don't know any. So here's just some thoughts about it in general:</p> <ul> <li>Mockito's approach is that if you can't mock something with Mockito, it probably is badly designed. I know it's not your code, and that actually leads to the next point:</li> <li>"Don't test the framework". Maybe you don't need the test it at all and it should be the responsibility of the frameworks creators. If it is smething thats needs to be tested, you could try to contribute a patch if it is an open source project.</li> <li>Mockito has its self-imposed limitations and might just not be the right tool. There are more powerful mocking frameworks that sure are capable of doing this.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload