Title: Bad test is produced when use concrete classes for implementing interface with generic · Issue #2450 · UnitTestBot/UTBotJava · GitHub
Open Graph Title: Bad test is produced when use concrete classes for implementing interface with generic · Issue #2450 · UnitTestBot/UTBotJava
X Title: Bad test is produced when use concrete classes for implementing interface with generic · Issue #2450 · UnitTestBot/UTBotJava
Description: Description When there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method. To Reproduce Use only fuzzer Generate test for method test. public class Imple...
Open Graph Description: Description When there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method. To Reproduce Use only fuzzer Generate ...
X Description: Description When there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method. To Reproduce Use only fuzzer Gener...
Opengraph URL: https://github.com/UnitTestBot/UTBotJava/issues/2450
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bad test is produced when use concrete classes for implementing interface with generic","articleBody":"**Description**\r\n\r\nWhen there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method.\r\n\r\n**To Reproduce**\r\n\r\n1. Use only fuzzer\r\n2. Generate test for method `test`.\r\n\r\n```java\r\npublic class Implementations {\r\n\r\n public interface A\u003cT\u003e {\r\n T getValue();\r\n }\r\n\r\n public static class AImpl implements A\u003cString\u003e {\r\n\r\n private final String value;\r\n\r\n public AImpl(String value) {\r\n this.value = value;\r\n }\r\n\r\n @Override\r\n public String getValue() {\r\n return value;\r\n }\r\n }\r\n\r\n public static int test(A\u003cInteger\u003e value) {\r\n if (value.getValue() \u003c 0) {\r\n return 0;\r\n }\r\n return value.getValue();\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior**\r\n\r\nThe only one method with null is generated, because there're no other options to create this class by fuzzer.\r\n\r\n**Actual behavior**\r\n\r\n2 tests are generated: with null and other with `AImpl`:\r\n\r\n```java\r\n @Test\r\n @DisplayName(\"test: arg_0 = AImpl(String) -\u003e throw ClassCastException\")\r\n public void testTestThrowsCCE() {\r\n AImpl aImpl = new AImpl(\"-3E\");\r\n \r\n /* This test fails because method [sanity.Implementations.test] produces [java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer]\r\n sanity.Implementations.test(Implementations.java:24) */\r\n Implementations.test(aImpl);\r\n }\r\n```\r\n\r\nThis test cannot be compiled.\r\n\r\n**Additional context**\r\n\r\nThe issue was introduced by 19fc16c9586b3bbce9c1812d6755bf47cfbb6df4\r\n","author":{"url":"https://github.com/Markoutte","@type":"Person","name":"Markoutte"},"datePublished":"2023-07-26T06:00:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2450/UTBotJava/issues/2450"}
| 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:89010be1-e427-ddb7-c20e-a801dc0f6ba8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E8C:126824:37C86FD:4BECEE7:698DD6D2 |
| html-safe-nonce | 19046bef956ee5028b2f8d36536479e1f02bed5b2d8256a7114c3a2b5409be51 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RThDOjEyNjgyNDozN0M4NkZEOjRCRUNFRTc6Njk4REQ2RDIiLCJ2aXNpdG9yX2lkIjoiNjIxODQ5NDk3NDI0NzE2MzYwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0104c20aa5281131c1b43da175b68e4bdf8df09ebd404c4181cc7465e0c0de1f |
| hovercard-subject-tag | issue:1821640252 |
| 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/2450/issue_layout |
| twitter:image | https://opengraph.githubassets.com/784577366b1fd3b034d5f8f51db1183e1f1ad035d96a1fcf0db4dd33fc5e9cc3/UnitTestBot/UTBotJava/issues/2450 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/784577366b1fd3b034d5f8f51db1183e1f1ad035d96a1fcf0db4dd33fc5e9cc3/UnitTestBot/UTBotJava/issues/2450 |
| og:image:alt | Description When there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method. To Reproduce Use only fuzzer Generate ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Markoutte |
| hostname | github.com |
| expected-hostname | github.com |
| None | d9c5a945db9d79f5476dbe75d3700f24739ef28ab02037163bdeac4050cd4ded |
| 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 | 1e3d09effb9f6299d5990409f03a0dfa8eca8595 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width