Skip to content

MockitoJUnitRunner.StrictStubs does not detect 'Unnecessary Stubbing' when inline mock maker is enabled #974

@tmurakami

Description

@tmurakami
  • mockito-core 2.7.13
  • OpenJDK 1.8.0_121
  • Ubuntu 16.10
  • Enable mock-maker-inline (or use mockito-inline artifact)

If running the following test, 'Unnecessary Stubbing' is not detected.

@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class MockitoTest {

    @Mock
    ArrayList<String> mock;

    @Test
    public void should_pass() {
        when(mock.get(0)).thenReturn("foo");
        assertEquals("foo", mock.get(0));
    }

    @Test
    public void should_detect_unnecessary_stubbing() {
        when(mock.get(1)).thenReturn("foo");
    }

}

In the above code, 'Unnecessary Stubbing' is detected by changing ArrayList to List.

    @Mock
//    ArrayList<String> mock;
    List<String> mock;

This problem does not occur with default mock maker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions