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

'Expecting actual not to be empty' when asserting array after filteredOn #497

Open
mitasov-ra opened this issue Apr 2, 2022 · 6 comments

Comments

@mitasov-ra
Copy link

Describe the bug

  1. AssertJ 2.33.0
  2. Create a small reproducible example and paste it the the bug report.
    assertThatJson("""[{"id": 123, "name": "abc"}, {"id": 432}]""")
      .isArray()
      .filteredOn("id", 123)
      .first()
      .node("name")
      .isEqualTo(value("abc"))
  3. Describe expected behavior
    Everything should be fine but I got:
    [Different value found in node ""] 
    Expecting actual not to be empty
    
@mitasov-ra mitasov-ra changed the title Expecting actual not to be empty when asserting array after filteredOn 'Expecting actual not to be empty' when asserting array after filteredOn Apr 2, 2022
@mitasov-ra
Copy link
Author

Seems like I've found the cause.

This works:

assertThatJson("""[{"id": 123, "name": "abc"}, {"id": 432}]""")
  .isArray()
  .filteredOn("id", BigDecimal(123))
  .first()
  .node("name")
  .isEqualTo(value("abc"))

@mitasov-ra
Copy link
Author

mitasov-ra commented Apr 2, 2022

I think such BigDecimal thing still counts as a bug.

Also it's obvious that assertion error message is a bit unclear

@lukas-krecan
Copy link
Owner

Hi, thanks for feedback.

  1. JsonUnit uses BigDecimals for numbers. filteredOn is AssertJ method and since int != BigDecimal the filter does not match
  2. The question is, why first did not fail on empty array, will look at it.

@mitasov-ra
Copy link
Author

  1. I think it is possible to tweak assertions with BigDecimal by making custom type for ACTUAL and overriding equals so it will accept integers.
  2. Yep, official AssertJ documentation says that first should fail on empty iterable

@lukas-krecan
Copy link
Owner

Just checked it. Expecting actual not to be empty is the exception form the first method. I will considering removing the message [Different value found in node ""] which is technically correct, but may be confusing in this case.

@mitasov-ra
Copy link
Author

mitasov-ra commented Apr 4, 2022

Just noticed that when using filteredOn on an POJO list then message containing something like [Filtered on ...] is added to error report. I think this is what missing.

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

No branches or pull requests

2 participants