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

Added Collection and Map matchers #36

Merged
merged 7 commits into from
May 27, 2017
Merged

Conversation

peterklijn
Copy link
Contributor

This PR adds matchers for Collection classes like List and Set and Map classes.

it("CollectionMatcher", () -> {
  final List<String> list = new LinkedList<>();
  final List<String> emptyList = new LinkedList<>();
  list.add("one");
  list.add("two");
  expect(list).toContain("one");
  expect(list).toNotContain("three");
  expect(list).toNotBeEmpty();
  expect(emptyList).toBeEmpty();
  expect(list).toHaveLength(2);
});

it("MapMatcher", () -> {
  final Map<String, Boolean> map = new HashMap<>();
  final Map<String, Boolean> emptyMap = new HashMap<>();
  map.put("one", false);
  map.put("two", true);
  expect(map).toContainKey("one");
  expect(map).toNotContainKey("three");
  expect(map).toContainValue(true);
  expect(emptyMap).toNotContainValue(true);
  expect(map).toNotBeEmpty();
  expect(emptyMap).toBeEmpty();
  expect(map).toHaveLength(2);
});

@mscharhag mscharhag merged commit d90f902 into mscharhag:master May 27, 2017
@mscharhag
Copy link
Owner

Hi @peterklijn,
thanks for your work :-)

I did a few small changes to your pull request in d49ee6d

  • Changed the method name toHaveLength(..) to toHaveSize(..). I think size is the more common term in java for the amount of items in a collection.
  • Added generic type parameters to MapMatcher so keys and values can be compared in a typesafe way (instead of Object)
  • Changed CollectionMatcher and MapMatcher so they can take null values (similar to StringMatcher).

@peterklijn
Copy link
Contributor Author

Thanks @mscharhag, happy it's merged :). Good point on the size vs length. I based it on Jasmine, but in Java size is indeed more common.

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

Successfully merging this pull request may close these issues.

2 participants