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

ASSERT.that(map) API #36

Closed
yujige opened this issue Aug 28, 2012 · 2 comments
Closed

ASSERT.that(map) API #36

yujige opened this issue Aug 28, 2012 · 2 comments
Milestone

Comments

@yujige
Copy link

yujige commented Aug 28, 2012

Some potential assertions:

void isEmpty();

IntegerSubject size();

CollectionSubject keys();

CollectionSubject values();

MapSubject contains(key, value);

That way, I can do:

ASSERT.that(map).size().isEqualTo(10);
ASSERT.that(map).keys().hasAnyOrder(a, b);
ASSERT.that(map)
.contains(key1, value1)
.contains(key2, value2)

@cgruber
Copy link
Contributor

cgruber commented Sep 5, 2012

So, some things aren't worth the API weight, I think. And in this case, I think a few of them are easier to just write:

ASSERT.that(map.size()).is(10);
ASSERT.that(map.keys()).has().allOf(a, b);

but some valid assertions directly on the map seem to be:

ASSERT.that(map).hasKey("foo").withValue("bar");

This is similar to the hasField("foo").withValue("bar"); pattern used in Subject itself, and it makes sense here.

AS to the others, it's sort of cute, but I'm just not sure it's worth it. Now the same thing can be said about all subject methods, and you can represent any of these propositions with assertTrue(somePredicate) in theory, so maybe I'm being too conservative here. I just feel like it doesn't add anything, where hasKey().withValue() seems to.

Thoughts? I'll certainly start there.

@ghost ghost assigned cgruber Sep 7, 2012
@cgruber
Copy link
Contributor

cgruber commented Sep 7, 2012

Initial MapSubject created and merged. Closing this. Feel free to open it or another if more features are desired on MapSubject than

hasKey()
hasKey().withValue()
lacksKey()
lacksValue()
isEmpty()
isNotEmpty()

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