Skip to content

Commit

Permalink
Improved: Use ‘contains’ matcher when possible
Browse files Browse the repository at this point in the history
(OFBIZ-10941)

It is more precise to use the ‘contains’ matcher when checking the
values, completeness and order of a collection.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1857960 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Apr 22, 2019
1 parent 47ea42c commit 26a2a5f
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
*******************************************************************************/
package org.apache.ofbiz.base.collections;

import static org.hamcrest.CoreMatchers.both;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

Expand All @@ -46,26 +43,26 @@ public void getEmpty() {
@Test
public void putSingleBasic() {
m.putSingle("foo", 0);
assertThat(m.get("foo"), hasItem(0));
assertThat(m.get("foo"), contains(0));
m.putSingle("foo", 1);
assertThat(m.get("foo"), both(hasItem(1)).and(not(hasItem(0))));
assertThat(m.get("foo"), contains(1));
}

@Test
public void addBasic() {
m.add("foo", 0);
assertThat(m.get("foo"), hasItem(0));
assertThat(m.get("foo"), contains(0));
m.add("foo", 1);
assertThat(m.get("foo"), hasItems(0, 1));
assertThat(m.get("foo"), contains(0, 1));
}

@Test
public void addWithPreviousContext() {
m.add("foo", 0);
m.push();
assertThat(m.get("foo"), hasItem(0));
assertThat(m.get("foo"), contains(0));
m.add("foo", 1);
assertThat(m.get("foo"), hasItems(0, 1));
assertThat(m.get("foo"), contains(0, 1));
}

@Test
Expand Down

0 comments on commit 26a2a5f

Please sign in to comment.