### Question:
OptionalFieldAppenderHelper { public List<EntityBody> getEntitySubList(List<EntityBody> list, String field, String value) { List<EntityBody> results = new ArrayList<EntityBody>(); if (list == null || field == null || value == null) { return results; } for (EntityBody e : list) { if (value.equals(e.get(field))) { results.add(e); } } return results; }  List<EntityBody> queryEntities(String resourceName, String key, List<String> values); List<EntityBody> queryEntities(String resourceName, NeutralQuery query); EntityBody getEntityFromList(List<EntityBody> list, String field, String value); List<EntityBody> getEntitySubList(List<EntityBody> list, String field, String value); List<String> getIdList(List<EntityBody> list, String field); Set<String> getSectionIds(List<EntityBody> entities);  }### Answer:
@Test public void testGetEntitySubList() { List<EntityBody> list = helper.getEntitySubList(createEntityList(true), "field1", "3"); assertEquals("Should match", 2, list.size()); assertEquals("Should match", "3", list.get(0).get("field1")); assertEquals("Should match", "3", list.get(1).get("field1")); list = helper.getEntitySubList(createEntityList(true), "field1", "0"); assertEquals("Should match", 0, list.size()); list = helper.getEntitySubList(null, "field1", "2"); assertEquals("Should match", 0, list.size()); list = helper.getEntitySubList(createEntityList(true), null, "2"); assertEquals("Should match", 0, list.size()); list = helper.getEntitySubList(createEntityList(true), "field1", null); assertEquals("Should match", 0, list.size()); list = helper.getEntitySubList(null, null, null); assertEquals("Should match", 0, list.size()); list = helper.getEntitySubList(createEntityList(true), "", ""); assertEquals("Should match", 0, list.size()); }