Skip to content

Injectable and Mock static methods of the same class #1

@ColinHebert

Description

@ColinHebert

This test used to work with JMockit 1.8, stopped working with JMockit 1.9

public class InetAddressTest {
    @Injectable
    private InetAddress mockInetAddress;

    @Test
    public void testInetAddressMock() throws Exception{
        new NonStrictExpectations(InetAddress.class) {{
            InetAddress.getLocalHost();
            result = mockInetAddress;
        }};

        Assert.assertSame(InetAddress.getLocalHost(), mockInetAddress);
    }
}

The problem here is that JMockit complains about the class being already mocked.

Class is already mocked: class java.net.InetAddress

This is fair enough, but what is the recommended approach when I need to mock a static method from a class while having an Injectable value as well?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions