Skip to content
Permalink
Browse files

Improved: Use ‘containsInAnyOrder’ matcher when possible

(OFBIZ-10941)

It is more precise to use ‘containsInAnyOrder’ matcher than checking
the presence of items and the size of the collections separately.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1857959 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Apr 22, 2019
1 parent 2b541d7 commit 47ea42c001a0c2b0e2aab7850731b8af0dc99958
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.base.collections;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@@ -56,8 +55,7 @@ public void containsValueBasic() {

@Test
public void valuesBasic() {
assertThat(adapter.values(), hasItems(0, 3));
assertThat(adapter.values().size(), is(2));
assertThat(adapter.values(), containsInAnyOrder(0, 3));
}

@Test
@@ -18,8 +18,7 @@
*******************************************************************************/
package org.apache.ofbiz.widget.renderer;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -58,8 +57,7 @@ public void fieldsToRenderBasic() {
fields.add(a);
ModelFormField b = ModelFormField.from(new ModelFormFieldBuilder().setName("B"));
fields.add(b);
assertThat(renderer.getUsedFields(context), hasItems(a, b));
assertThat(renderer.getUsedFields(context).size(), is(2));
assertThat(renderer.getUsedFields(context), containsInAnyOrder(a, b));
}

@Test
@@ -70,8 +68,7 @@ public void fieldsToRenderDuplicates() {
fields.add(b);
ModelFormField a2 = ModelFormField.from(new ModelFormFieldBuilder().setName("A"));
fields.add(a2);
assertThat(renderer.getUsedFields(context), hasItems(a1, a2, b));
assertThat(renderer.getUsedFields(context).size(), is(3));
assertThat(renderer.getUsedFields(context), containsInAnyOrder(a1, a2, b));
}

@Test
@@ -82,8 +79,7 @@ public void fieldsToRenderBasicUseWhen() {
ModelFormField a2 = ModelFormField.from(new ModelFormFieldBuilder().setName("A").setUseWhen("false"));
fields.add(a2);
useWhenFields.add(a2.getName());
assertThat(renderer.getUsedFields(context), hasItems(a1, a2));
assertThat(renderer.getUsedFields(context).size(), is(2));
assertThat(renderer.getUsedFields(context), containsInAnyOrder(a1, a2));
}

@Test
@@ -97,8 +93,7 @@ public void fieldsToRenderDuplicatesUseWhen() {
ModelFormField a3 = ModelFormField.from(new ModelFormFieldBuilder().setName("A").setUseWhen("true"));
fields.add(a3);
useWhenFields.add(a3.getName());
assertThat(renderer.getUsedFields(context), hasItems(a1, a2));
assertThat(renderer.getUsedFields(context).size(), is(2));
assertThat(renderer.getUsedFields(context), containsInAnyOrder(a1, a2));
}

}

0 comments on commit 47ea42c

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