Skip to content

MockitoException is expected to be thrown in Unit tests, but the test passes #2549

Closed
@alisevych

Description

@alisevych

Description

Generated Unit test for Spring project is expected to throw MockitoException, but the test passes.

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Open Medical-Web-App project
  3. Generate tests for MirfController with Unit tests and MedicalWebApp configuration selected
  4. Run ERROR SUITE for method getResultFromPipeline

Expected behavior

There should be no such test present on MockitoException.
It should be included into Successful executions suite (or excluded as a duplicate).

Actual behavior

The test on MockitoException passes.

Screenshots, logs

    @Test
    public void testGetResultFromPipeline1() throws Exception {
        ((doNothing()).when(loggerMock)).info(any(String.class), any(Object.class), any(Object.class));
        ArrayList arrayList = new ArrayList();
        PipelineJob pipelineJob = ((PipelineJob) createInstance("com.app.medicalwebapp.model.PipelineJob"));
        String string = "";
        pipelineJob.setMirfSessionid(string);
        arrayList.add(pipelineJob);
        (when(pipelineJobRepositoryMock.findAll())).thenReturn(arrayList);
        (when(pipelineJobRepositoryMock.findByMirfSessionid(any()))).thenReturn(arrayList);
        MultipartFile resultZipFileMock = mock(MultipartFile.class);
        InputStream inputStreamMock = mock(InputStream.class);
        byte[] byteArray = {
                (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
                (byte) 0
        };
        (when(inputStreamMock.readAllBytes())).thenReturn(byteArray);
        (when(resultZipFileMock.getInputStream())).thenReturn(inputStreamMock);
        (when(resultZipFileMock.getSize())).thenReturn(0L);
        
        /* This test fails because method [com.app.medicalwebapp.clients.mirf.MirfController.getResultFromPipeline] produces [org.mockito.exceptions.base.MockitoException: 
        Cannot call abstract real method on java object!
        Calling real methods is only possible when mocking non abstract method.
          //correct example:
          when(mockOfConcreteClass.nonAbstractMethod()).thenCallRealMethod();]
            org.utbot.instrumentation.instrumentation.execution.constructors.InstrumentationContextAwareValueConstructor$generateMockitoAnswer$1.answer(InstrumentationContextAwareValueConstructor.kt:217)
            com.app.medicalwebapp.clients.mirf.MirfController.getResultFromPipeline(MirfController.java:65) */
        mirfController.getResultFromPipeline(null, resultZipFileMock);
    }

Environment

IntelliJ IDEA version - Ultimate 2023.2
Project - Maven
JDK - 11

Metadata

Metadata

Assignees

Labels

comp-springIssue is related to Spring projects supportctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions