question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum comparison with String is not working with recursive assertion

See original GitHub issue

Summary

Comparison of enum with string fails with recursive assertion and strictTypeChecking as false. I would expect below code to be run successfully.

actual and expected objects and their fields were compared field by field recursively even if they were not of the same type - as per error, actual and expected values are same (CAR in below example) and test case should pass.

Example

public class TestEnumWithString {

    @Test
    public void testEnumWithString() {
        assertThat(Vehicle.CAR).usingRecursiveComparison().isEqualTo("CAR");
    }
}

enum Vehicle {
    CAR
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vimalbera92commented, May 19, 2022

@joel-costigliola - I’m using latest version 3.22.0.

0reactions
joel-costigliolacommented, Aug 7, 2022

Closing this issue as we can register specific comparison/equals for types or fields which I think cover the use case. Happy to reopen if that turns our not to be true.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enum comparison with String is not working with recursive ...
Comparison of enum with string fails with recursive assertion and strictTypeChecking as false. I would expect below code to be run successfully.
Read more >
How to compare a string with a python enum? - Stack Overflow
Solved my problem. Though I could not use Signal(brain_detected_colour) is Signal.red (mentioned at the end of the answer, for when an enum is ......
Read more >
Java static code analysis: Enum values should be compared ...
Enum values should be compared with "==" · provides the same expected comparison (content) as equals · is more null-safe than equals() ·...
Read more >
AssertJ - fluent assertions java library - GitHub Pages
Example for String assertions: ... Fix Recursive comparison that did not compare enums as they don't have fields, now it compares enums with...
Read more >
Working with enums in Go | Emir Ribic
IllegalArgumentException: No enum constant . With Go, it's different. Most often you create a custom type ( LeaveType ) and define constants of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found