Skip to content

HashMap with Enum as key - test generation fails #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alisevych opened this issue Jul 6, 2022 · 3 comments · Fixed by #1228
Closed

HashMap with Enum as key - test generation fails #436

alisevych opened this issue Jul 6, 2022 · 3 comments · Fixed by #1228
Assignees
Labels
ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@alisevych
Copy link
Member

alisevych commented Jul 6, 2022

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.

@alisevych alisevych added the ctg-bug Issue is a bug label Jul 6, 2022
@dtim
Copy link
Collaborator

dtim commented Jul 6, 2022

Related to #230, #414

@dtim
Copy link
Collaborator

dtim commented Jul 28, 2022

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;
    }

dtim added a commit that referenced this issue Aug 4, 2022
dtim added a commit that referenced this issue Aug 5, 2022
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
@JaneEugenia JaneEugenia moved this to Todo in UTBot Java Sep 9, 2022
@denis-fokin denis-fokin added the spec-release-tailings Failed to include in the current release, let's include it in the next one label Sep 28, 2022
@denis-fokin denis-fokin removed this from the Release preparation milestone Sep 28, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Oct 7, 2022
@CaelmBleidd CaelmBleidd assigned CaelmBleidd and unassigned dtim Oct 13, 2022
@CaelmBleidd
Copy link
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));
}

@JaneEugenia JaneEugenia moved this from Todo to In Progress in UTBot Java Oct 19, 2022
Repository owner moved this from In Progress to Done in UTBot Java Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants