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

AssertJ cannot compare arrays in maps #3315

Closed
asolntsev opened this issue Jan 1, 2024 · 4 comments · Fixed by #3321
Closed

AssertJ cannot compare arrays in maps #3315

asolntsev opened this issue Jan 1, 2024 · 4 comments · Fixed by #3321
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@asolntsev
Copy link
Contributor

Describe the bug
A clear and concise description of what the bug is.

  • assertj core version: 3.25.0
  • java version: 17
  • test framework version: JUnit 5.10.1
  • os (if relevant): MacOS Sonoma 14.2.1

Test case reproducing the bug

This code worked in AssertJ 3.24.2, but fails in AssertJ 3.25.0:

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import java.util.Map;

  @Test
  void fails() {
    assertThat(Map.of("firstName", new String[] {"Bob"}))
      .containsExactlyEntriesOf(Map.of("firstName", new String[] {"Bob"}));
  }

This test fails with the error message:

    java.lang.AssertionError: 
    Actual and expected have the same elements but not in the same order, at index 0 actual element was:
      "firstName"=["Bob"]
    whereas expected element was:
      "firstName"=["Bob"]
        at play.utils.UtilsTest.fails(UtilsTest.java:50)
@scordio scordio added the type: regression A regression from a previous release label Jan 1, 2024
@scordio scordio added this to the 3.25.1 milestone Jan 1, 2024
@scordio
Copy link
Member

scordio commented Jan 1, 2024

Thanks for reporting it, @asolntsev!

@scordio
Copy link
Member

scordio commented Jan 2, 2024

The change that causes the issue is 498ee5b.

@scordio
Copy link
Member

scordio commented Jan 2, 2024

Here we assume that the map value can be compared with equals:

if (!actual.containsKey(entries[0].getKey()) || !actual.containsValue(entries[0].getValue())) {

This cannot work with array values as equals compares identity and not the array's content.

@scordio
Copy link
Member

scordio commented Jan 2, 2024

Team decision: 498ee5b should be reverted and #2165 should be addressed again with the knowledge gathered from this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
2 participants