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.

Extend `GenericCollectionAssertions` to include a `ContainInConsecutiveOrder`

See original GitHub issue

Description

We were writing tests where we needed to check if one collection contained another in order. For this, we used ContainInOrder.

However, we found that because ContainInOrder doesn’t check that the items are consecutive we could introduce mutations in the code and our tests would still pass.

To solve this we have made a new method in the same class, GenericCollectionAssertions, called ContainInConsecutiveOrder. This is a stricter version of the current check, adding the check that the expected items all appear in consecutive order. For completeness, we also introduced the opposite NotContainInConsecutiveOrder.

The API change is an extension to the API, with, as far as I can see, no breaking changes.

We have implemented these changes, with associated tests, in a branch and would like to submit a PR.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
jnyrupcommented, Jul 23, 2022

I’m good with ContainInConsecutiveOrder.

@lg2de Thanks for your perspectives (here and elsewhere in the repo). I’m happy to have your extra set of eyes to ensure we leave no stone unturned.

2reactions
dennisdoomencommented, Jul 22, 2022

Although I don’t dislike the proposal, my problem is that we already took a certain (ad-hoc) path where we have distinct methods for distinct goals. If we would have taken this design principle as a starting point, we could have done that. And we still can, but it would be a major breaking change that would require a major review of all APIs to see what they would look like in a major new version. Not only would this require a lot of work and planning, it would also be a major breaking change for our installed base without gaining a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - CollectionAssert use with generics?
You can use CollectionAssert with generic collections. The trick is to understand that the CollectionAssert methods operate on ICollection ...
Read more >
Fluent Assertions 6.0, the biggest release ever
If the collection involved deals with anything else than strings, we still have plenty to offer. For example, Satisfy() will allow you to ......
Read more >
`contains` check on a Collection<? extends Base> gives ...
Is there solution for that assertion case in AssertJ already? Example. public class GenericsHell { void aMethod() { List<? extends ...
Read more >
"Generic.List" instances should not be part of public APIs
System.Collections.Generic.List<T> is a generic collection that is designed for performance and not inheritance. For example, it does not contain virtual ...
Read more >
Releases - Fluent Assertions
Added ContainInConsecutiveOrder and NotContainInConsecutiveOrder assertions to check if a collection contains items in a specific order and to be ...
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