GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JDK17: UtBot tries to mock unexported packages and creates uncompilable tests · Issue #2070 · UnitTestBot/UTBotJava

JDK17: UtBot tries to mock unexported packages and creates uncompilable tests #2070

New issue
Copy link
New issue
Copy link
Open
Open
JDK17: UtBot tries to mock unexported packages and creates uncompilable tests#2070
Copy link
Assignees
sergeypospelov
Labels
comp-codegenIssue is related to code generatorIssue is related to code generatorctg-bugIssue is a bugIssue is a bug

Description

@tyuldashev
tyuldashev
opened on Mar 29, 2023
Issue body actions

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;
    }
  1. Set JDK 17 as project JDK
  2. Invoke test generation for code sample above, use "Mock everything outside the package" option.
  3. 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)
image

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

Activity

  1. tyuldashev
    added
    ctg-bugIssue is a bugIssue is a bug
    comp-codegenIssue is related to code generatorIssue is related to code generator
    on Mar 29, 2023
  2. tyuldashev
    assigned
    sergeypospelov
    on Mar 29, 2023
  3. tyuldashev
    added this to UTBot Javaon Mar 29, 2023
  4. github-project-automation
    moved this to Todo in UTBot Javaon Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sergeypospelov
    sergeypospelov

Labels

comp-codegenIssue is related to code generatorIssue is related to code generatorctg-bugIssue is a bugIssue is a bug

Type

No type

Projects

  • UTBot Java
    Status
    Todo
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.