Open
Description
Description
On sample code which works with network UtBot tries to create mockStatic(sun.net.util.IPAddressUtil.class)
while IPAddressUtill
is not exported from JDK module, so resulting tests are not compilable.
To Reproduce
Steps to reproduce the behavior:
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
...
public int connect(Socket socket) throws IOException {
socket.connect(new InetSocketAddress("0.0.0.0", 22));
return 0;
}
- Set JDK 17 as project JDK
- Invoke test generation for code sample above, use "Mock everything outside the package" option.
- Open generated tests
Expected behavior
Generated test are compilable.
Actual behavior
Generated test is not compilable, because uses internal JDK class
@Test(description = "connect: -> return 0")
public void testConnect_ReturnZero() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException {
org.mockito.MockedStatic mockedStatic = null;
try {
mockedStatic = mockStatic(sun.net.util.IPAddressUtil.class);
(mockedStatic.when(() -> sun.net.util.IPAddressUtil.digit(anyChar(), anyInt()))).thenReturn(0);
byte[] byteArray = new byte[16];
(mockedStatic.when(() -> sun.net.util.IPAddressUtil.validateNumericFormatV4(any()))).thenReturn(byteArray);
...
Visual proofs (screenshots, logs, images)
Additional context
It seems we have two options to resolve that problem:
- Detect somehow that class is not exported and don't generate such tests.
- Generate test as is but add some comment that user has to add those
--add-exports
manually to test run configuration, see the same suggestion for--add-opens
. And update the docs as well - #2047
Metadata
Metadata
Assignees
Type
Projects
Status
Todo