Seeing issue with org.mockito.exceptions.misusing.NotAMockException

Viewed 318

Seeing an issue with spy and auto-wire along with Extend(SpringExtention)

Argument should be a mock, but is: class org.springframework.data.jpa.repository.support.SimpleJpaRepository

@ExtendWith(SpringExtention.class)
@SpringBootTest(classes = TestServer.class)
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("test")
@Transactional
SampleServiceTest {
        
    @Spy
    @Autowire
    private TestRepo repo;
    @Mock
    SpecialTest test;
    @Mock
    SpecialTest1 test1;
    @InjectMock
    TestServiceTest testService;
        
    @InjectMock
    SampleServiceTest sampleServiceTest;
    
    @BeforeEach()
    void setup () {
        openMocks(this);
        when(testService.getId()).thenReturn(test);
        when(testService.getId()).thenReturn(test1);
    }
    
    @Test
    void test () {
    
    }

When I am using the spring-boot: 2.4.1 I am seeing the above issue.

0 Answers
Related