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

Implement visitor for migration of Assert.assertEquals(Iterator, Iterator, String) #1

Closed
Philzen opened this issue Jun 11, 2024 · 1 comment

Comments

@Philzen
Copy link
Owner

Philzen commented Jun 11, 2024

JUnit 5 does not implement dedicated handling of iterators in Assertion.assertEquals(…) – i've done a quick UnitTest comparison, and if simply replaced, a test case that passed in TestNG will fail after the migration.

Following replacement works:

Before

void testMethod() {
    Iterator<?> actualIterator = Arrays.asList("Bar", "Foo").iterator();
    Iterator<?> expectedIterator = Arrays.asList("Bar", "Foo").iterator();
    
    Assert.assertEquals(actualIterator, expectedIterator, "Foo = equal");
}

After

void testMethod() {
    Iterator<?> actualIterator = Arrays.asList("Bar", "Foo").iterator();
    Iterator<?> expectedIterator = Arrays.asList("Bar", "Foo").iterator();
    
    Collection<Object> actualValues = new ArrayList<>();
    Collection<Object> expectedValues = new ArrayList<>();
    
    actual.forEachRemaining(actualValues::add);
    expected.forEachRemaining(expectedValues::add);
    
    Assertions.assertIterableEquals(iteratorElements, iterator2Elements, "Foo = equal");
}

IMHO it's unfortunately not possible to integrate this replacement into the Refaster Recipe, as that can only replace existing code with a single statement, therefore we'll need a dedicated visitor.

@Philzen
Copy link
Owner Author

Philzen commented Jun 14, 2024

Solved via d15e96c, thus will be implemented as part of #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant