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

more assertions on collection sizes #301

Closed
jstrachan opened this issue Dec 18, 2014 · 8 comments
Closed

more assertions on collection sizes #301

jstrachan opened this issue Dec 18, 2014 · 8 comments
Milestone

Comments

@jstrachan
Copy link
Contributor

I figured on a ListAssert I'd be able to do things like...

assertThat(someList).size().isGreaterThan(4);

i.e. that a method size() would be available returning the IntegerAssert for further more expressive assertions on a List size.

I can submit a PR if you like?

@AlexBischof
Copy link
Contributor

I like that feature but size() should be left out. It would be consistent with the other classes (e.g. ByteAssert).

@jstrachan
Copy link
Contributor Author

Sorry I didn't grok how adding a size() method would not be consistent with ByteAssert (which is a byte, not a collection with a size value); is it the name "size" you're objecting to? Got a better idea for the name of the function?

@jstrachan
Copy link
Contributor Author

how about assertSize()? as in:

assertThat(someList).assertSize().isGreaterThan(4);

to make it clear its different from the size() method on a List but related to it?

@jstrachan
Copy link
Contributor Author

or hasSize()?

@joel-costigliola
Copy link
Member

there is already an hasSize() assertion.

I must say I don't see much value in the proposal over what you can already write:

assertThat(someList.size()).isGreaterThan(4);

Do you have others use case in mind ?

@jstrachan
Copy link
Contributor Author

How do you get the java.util.List from a ListAssert so that you can call .size() on it so that you can use it on an assertThat() call?

If there was a way to get the List value out of ListAssert, then thats an OK approach - but its not very smart-complete-in-your-IDE friendly.

I just figured, in the interest of IDE completion; having a way to navigate from ListAssert to an IntegerAssert for the size of a List seems to make the cleanest IDE-friendly DSL.

e.g. here's an example....
https://github.com/fabric8io/fabric8/blob/master/components/kubernetes-assertions/src/test/java/io/fabric8/kubernetes/assertions/Example.java#L38

through the DSL I can find a List of pods which are a ListAssert - however there's no way I can find to make an assertion on the size of that list - other than by doing a totally separate query to find the real List thats inside the ListAssert; which just seems odd. Unless I'm missing something?

@joel-costigliola
Copy link
Member

Ok why not.
In you case I would just add more custom assertions.

PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 13, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Mar 14, 2016
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Apr 17, 2016
tried change to "enable fluent assertions on size of iterable"
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Apr 17, 2016
tried change to "enable fluent assertions on size of iterable"
PascalSchumacher added a commit to PascalSchumacher/assertj-core that referenced this issue Apr 18, 2016
@joel-costigliola joel-costigliola added this to the 2.5.0 milestone May 28, 2016
@joel-costigliola
Copy link
Member

Fixed.

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

3 participants