MockedStatic is not mocking one static method

262 Views Asked by At

I am using MockedStatic in static Util.parse(string, class) method but when I am running is not mocking and its printing NULL, basically it should give me a static file as a response that I loaded before, for that I am using MockedStatic 3.4.4, or I am doing something wrong, if someone can help me with that.

public List<ServiceRecord> getListServices(Services.Type type, String env) throws Exception {

        Swagger swagger2 = Util.parse("{ss}", Swagger.class);
        System.out.println(swagger2);

this is my test class:

@RunWith(MockitoJUnitRunner.class)
public class RemoteServicesTest {
...     
@Test
 public void getListServicesLegacyTest() throws Exception {

        Swagger swaggerMock = IoUtil.readFromFile("mock.json", Swagger.class);


        try(MockedStatic<Util> mockUtil2 = Mockito.mockStatic(Util.class)) {
            mockUtil2.when(() -> Util.parse(eq("{ss}"), eq(Swagger.class))).thenReturn(swaggerMock);
            List<ServiceRecord> serviceRecordList2 = remoteCloudLegacyServices.getListServices(Services.Type.LEGACY, environment.getEnv());
        }

my pom.xml

 <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-inline</artifactId>
            <version>3.4.4</version>
            <scope>test</scope>
        </dependency>
0

There are 0 best solutions below