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

Clean Up produces compile error for JUnit5 assertion (possibly generics compile issue) #1535

Closed
guw opened this issue Jul 23, 2024 · 0 comments · Fixed by #1674
Closed

Clean Up produces compile error for JUnit5 assertion (possibly generics compile issue) #1535

guw opened this issue Jul 23, 2024 · 0 comments · Fixed by #1674
Assignees
Labels
bug Something isn't working
Milestone

Comments

@guw
Copy link
Contributor

guw commented Jul 23, 2024

The following snippet:

    private void assertIteratorProducesExpectedList(
            List<String> expectedList,
            Iterator<String> rankedListIterator) {
        org.junit.jupiter.api.Assertions.assertIterableEquals(expectedList, new Iterable<String>() {
            @Override
            public Iterator<String> iterator() {
                return rankedListIterator;
            }
        });
    }

Gets clean up into:

    private void assertIteratorProducesExpectedList(
            List<String> expectedList,
            Iterator<String> rankedListIterator) {
        org.junit.jupiter.api.Assertions.assertIterableEquals(expectedList, () -> rankedListIterator);
    }

The latter produces two compile errors in Eclipse:

  1. Type mismatch: cannot convert from Iterator<String> to Iterator<Object>
  2. The method assertIterableEquals(Iterable<?>, Iterable<?>) in the type Assertions is not applicable for the arguments (List<String>, () -> {})

Version: 2024-06 (4.32.0)
Build id: 20240606-1231

Note, it might be a type inference problem. The code compiles fine if I introduce a local variable assignment.

    private void assertIteratorProducesExpectedList(
            List<String> expectedList,
            Iterator<String> rankedListIterator) {
        Iterable<String> iterable = () -> rankedListIterator;
        assertIterableEquals(expectedList, iterable);
    }
@guw guw changed the title Clean Up produced compile error Clean Up produces compile error for JUnit5 assertion (possibly generics compile issue) Jul 23, 2024
@iloveeclipse iloveeclipse transferred this issue from eclipse-jdt/eclipse.jdt.core Jul 23, 2024
@jjohnstn jjohnstn self-assigned this Sep 25, 2024
@jjohnstn jjohnstn added the bug Something isn't working label Sep 25, 2024
jjohnstn added a commit to jjohnstn/eclipse.jdt.ui-1 that referenced this issue Sep 26, 2024
- modify LambdaExressionsFixCore to add a cast if the lambda will
  end up as an argument that is supposed to be a wildcard type and
  the bound is not compatible with the initial class instance
  creation type argument
- add new tests to CleanUpTest1d8
- fixes eclipse-jdt#1535
@jjohnstn jjohnstn added this to the 4.34 M1 milestone Sep 26, 2024
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
None yet
Development

Successfully merging a pull request may close this issue.

2 participants