Skip to content
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

Bug adding import to a list of imports containing duplicate imports #4196

Closed
nguyenhoan opened this issue May 17, 2024 · 0 comments · Fixed by #4197
Closed

Bug adding import to a list of imports containing duplicate imports #4196

nguyenhoan opened this issue May 17, 2024 · 0 comments · Fixed by #4197
Assignees
Labels
bug Something isn't working

Comments

@nguyenhoan
Copy link
Contributor

What version of OpenRewrite are you using?

I am using the latest version from the tip of GitHub's main branch.

How are you running OpenRewrite?

What is the smallest, simplest way to reproduce the problem?

Add the below test case to org.openrewrite.java.style.ImportLayoutStyleTest

    @Test
    void testAddImport() {
        ImportLayoutStyle style = new ImportLayoutStyle(
          Integer.MAX_VALUE, Integer.MAX_VALUE, Collections.emptyList(), Collections.emptyList());
        JRightPadded<J.Import> import1 = new JRightPadded<>(
          new J.Import(
            randomId(),
            Space.EMPTY,
            Markers.EMPTY,
            new JLeftPadded<>(Space.SINGLE_SPACE, true, Markers.EMPTY),
            TypeTree.build("pkg.Clazz.MEMBER_1").withPrefix(Space.SINGLE_SPACE),
            null),
          Space.EMPTY,
          Markers.EMPTY);
        JRightPadded<J.Import> import2 = new JRightPadded<>(
          new J.Import(
            randomId(),
            Space.EMPTY,
            Markers.EMPTY,
            new JLeftPadded<>(Space.SINGLE_SPACE, true, Markers.EMPTY),
            TypeTree.build("pkg.Clazz.MEMBER_1").withPrefix(Space.SINGLE_SPACE),
            null),
          Space.EMPTY,
          Markers.EMPTY);
        J.Import importToAdd = new J.Import(
          randomId(),
          Space.EMPTY,
          Markers.EMPTY,
          new JLeftPadded<>(Space.SINGLE_SPACE, true, Markers.EMPTY),
          TypeTree.build("pkg.Clazz.MEMBER_2").withPrefix(Space.SINGLE_SPACE),
          null);
        assertThat(style.addImport(List.of(import1, import2), importToAdd, null, Collections.emptyList()))
          .containsExactlyInAnyOrder(import1, import1, new JRightPadded<>(importToAdd, Space.EMPTY, Markers.EMPTY));
    }

What did you expect to see?

containsExactlyInAnyOrder(import1, import1, new JRightPadded<>(importToAdd, Space.EMPTY, Markers.EMPTY))

What did you see instead?

containsExactlyInAnyOrder(import1, import1)

What is the full stack trace of any errors you encountered?

Are you interested in contributing a fix to OpenRewrite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant