Skip to content
Permalink
Browse files

Improved: Use ‘contains’ matcher when possible

(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 26a2a5fa4300b71cd03a222860eee77f2f3a4f89
@@ -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;

@@ -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

0 comments on commit 26a2a5f

Please sign in to comment.
You can’t perform that action at this time.