Skip to content

HashMap with Enum as key - test generation fails #436

Closed

Description

@alisevych

Description

Test generation fails for a method with HashMap using Enum as key.

To Reproduce

Steps to reproduce the behavior:

  1. IntelliJ IDEA with UTBotJava plugin installed
  2. A project with JDK 8/11 is opened
  3. Add the following class:
public class MapWithEnum {

    public void createMapWithEnum() {
        Map<WorkDays, Integer> map = new HashMap<>();
        map.put(WorkDays.Monday, 112);
        map.put(WorkDays.Tuesday, 354);
        map.put(WorkDays.Friday, 567);
        map.remove(WorkDays.Tuesday);
    }

    public enum WorkDays {
        Monday,
        Tuesday,
        Wednesday,
        Thursday,
        Friday
    }
}
  1. Run Generating tests with UTBot... for this class

Expected behavior

Tests are supposed to be generated.

Actual behavior

"Failed to generate unit tests for class MapWithEnum" error popup is shown in IDEA.
It is shown immediately after test generation is started.
Map.remove() method is crucial for the issue - without it generation passes.

Visual proofs (screenshots, logs, images)

Map with Enum as key

Environment

Windows 10 Pro
IntelliJ IDEA 2022.1.3
checked on JDK 8 and 11, Gradle, Maven projects - same error

Additional context

Adding some input parameters to the method helps - fuzzer is generating tests.

Map.remove() method is crucial for the issue - without it generation passes.

Map with Enum as values - test generation passes.

Activity

  1. dtim commented on Jul 6, 2022

    @dtim
    Collaborator

    Related to #230, #414

  2. dtim commented on Jul 28, 2022

    @dtim
    Collaborator

    It seems that the problem is not enum-specific. The following example does not work as well:

        public HashMap<String, Integer> createMapWithString() {
            HashMap<String, Integer> map = new HashMap<>();
            map.put("tuesday", 354);
            map.remove("tuesday");
            return map;
        }
    
  3. added this to the Release preparation milestone on Sep 7, 2022
  4. added
    spec-release-tailingsFailed to include in the current release, let's include it in the next one
    on Sep 28, 2022
  5. removed this from the Release preparation milestone on Sep 28, 2022
  6. added this to the 2022.12 Release milestone on Oct 7, 2022
  7. CaelmBleidd commented on Oct 19, 2022

    @CaelmBleidd
    Member

    Looks like it doesn't work when key and value have different types. Following examples doesn't work as well:

    Integer mapPutAndGet() {
      Map<Long, Integer> values = new HashMap<>();
    
      values.put(new Long(1), new Integer(1));
    
      return values.get(new Long(1));
    }
  8. moved this from Todo to In Progress in UTBot Javaon Oct 19, 2022
  9. Repository owner moved this from In Progress to Done in UTBot Javaon Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions