Title: JDK17: UtBot tries to mock unexported packages and creates uncompilable tests · Issue #2070 · UnitTestBot/UTBotJava · GitHub
Open Graph Title: JDK17: UtBot tries to mock unexported packages and creates uncompilable tests · Issue #2070 · UnitTestBot/UTBotJava
X Title: JDK17: UtBot tries to mock unexported packages and creates uncompilable tests · Issue #2070 · UnitTestBot/UTBotJava
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 rep...
Open Graph 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 n...
X 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 n...
Opengraph URL: https://github.com/UnitTestBot/UTBotJava/issues/2070
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JDK17: UtBot tries to mock unexported packages and creates uncompilable tests","articleBody":"**Description**\r\n\r\nOn 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.\r\n\r\n**To Reproduce**\r\n\r\nSteps to reproduce the behavior:\r\n\r\n```java\r\nimport java.io.IOException;\r\nimport java.net.InetSocketAddress;\r\nimport java.net.Socket;\r\n...\r\n public int connect(Socket socket) throws IOException {\r\n socket.connect(new InetSocketAddress(\"0.0.0.0\", 22));\r\n return 0;\r\n }\r\n```\r\n\r\n1. Set JDK 17 as project JDK\r\n2. Invoke test generation for code sample above, use **\"Mock everything outside the package\"** option.\r\n3. Open generated tests\r\n\r\n**Expected behavior**\r\n\r\nGenerated test are compilable.\r\n\r\n**Actual behavior**\r\n\r\nGenerated test is not compilable, because uses internal JDK class\r\n```java\r\n @Test(description = \"connect: -\u003e return 0\")\r\n public void testConnect_ReturnZero() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException {\r\n org.mockito.MockedStatic mockedStatic = null;\r\n try {\r\n mockedStatic = mockStatic(sun.net.util.IPAddressUtil.class);\r\n (mockedStatic.when(() -\u003e sun.net.util.IPAddressUtil.digit(anyChar(), anyInt()))).thenReturn(0);\r\n byte[] byteArray = new byte[16];\r\n (mockedStatic.when(() -\u003e sun.net.util.IPAddressUtil.validateNumericFormatV4(any()))).thenReturn(byteArray);\r\n...\r\n```\r\n\r\n**Visual proofs (screenshots, logs, images)**\r\n\r\n\r\n\r\n**Additional context**\r\n\r\nIt seems we have two options to resolve that problem:\r\n * Detect somehow that class is not exported and don't generate such tests.\r\n * 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](https://github.com/UnitTestBot/UTBotJava/issues/2026#issuecomment-1481386538) for `--add-opens`. And update the docs as well - [#2047](https://github.com/UnitTestBot/UTBotJava/issues/2047)\r\n","author":{"url":"https://github.com/tyuldashev","@type":"Person","name":"tyuldashev"},"datePublished":"2023-03-29T12:55:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2070/UTBotJava/issues/2070"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:50eb022f-cf95-fa2b-419c-a7c6dfe0fe63 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D126:32AED0:268824:345785:698F0C57 |
| html-safe-nonce | 4fe3fdfa586e9ac35fbcb23c2393bc891c262652f922368e81bbb4139bd759c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTI2OjMyQUVEMDoyNjg4MjQ6MzQ1Nzg1OjY5OEYwQzU3IiwidmlzaXRvcl9pZCI6IjgyOTgwODM4MDA3MDY5MTEzMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dcee3345996e146b4cea811fbc554d554ae831db828c4dd01c374ca6269a792e |
| hovercard-subject-tag | issue:1645754963 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/UnitTestBot/UTBotJava/2070/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c85927fe86d66079091ac47ff7e3b6081624c099804149fb3a96ef2cd81e8ab2/UnitTestBot/UTBotJava/issues/2070 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c85927fe86d66079091ac47ff7e3b6081624c099804149fb3a96ef2cd81e8ab2/UnitTestBot/UTBotJava/issues/2070 |
| og:image:alt | 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 n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tyuldashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2da1a0d1318592c9965539b12269c4641177dfabfc86c3807992efb13e1d96ff |
| turbo-cache-control | no-preview |
| go-import | github.com/UnitTestBot/UTBotJava git https://github.com/UnitTestBot/UTBotJava.git |
| octolytics-dimension-user_id | 87413538 |
| octolytics-dimension-user_login | UnitTestBot |
| octolytics-dimension-repository_id | 480810501 |
| octolytics-dimension-repository_nwo | UnitTestBot/UTBotJava |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 480810501 |
| octolytics-dimension-repository_network_root_nwo | UnitTestBot/UTBotJava |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 66d26b1a7f81bd3ffe8d0f16abab43f6e64fd21a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width