ViewUtil { public static View removeGroups(final View view, final String... groups) { if (null == view) { throw new IllegalArgumentException("View cannot be null"); } final LinkedHashMap<String, ViewElementDefinition> entities = new LinkedHashMap<>(view.getEntities()); final LinkedHashMap<String, ViewElementDefinition> edges = new LinkedHashMap<>(view.getEdges()); if (null != groups) { for (final String group : groups) { entities.remove(group); edges.remove(group); } } else { throw new IllegalArgumentException("Specified group(s) to remove is null"); } return new View.Builder() .merge(view) .entities(entities) .edges(edges) .build(); } private  ViewUtil(); static void removeProperties(final View view, final Element element); static void removeProperties(final ViewElementDefinition elDef, final Element element); static void removeProperties(final ViewElementDefinition elDef, final Properties properties); static View removeGroups(final View view, final String... groups);  }
@Test public void shouldRemoveGroupFromView() { View view = new View.Builder() .edge(TestGroups.EDGE) .entity(TestGroups.ENTITY) .build(); assertEquals(2, view.getGroups().size()); view = ViewUtil.removeGroups(view, TestGroups.EDGE); assertFalse(view.getGroups().contains(TestGroups.EDGE)); assertEquals(1, view.getGroups().size()); view = ViewUtil.removeGroups(view, TestGroups.ENTITY); assertFalse(view.getGroups().contains(TestGroups.ENTITY)); assertEquals(0, view.getGroups().size()); }
@Test public void shouldIgnoreRemovingGroupFromViewWhenNotSet() { final View view = new View.Builder() .edge(TestGroups.EDGE) .build(); final View viewAfterRemove = ViewUtil.removeGroups(view, TestGroups.ENTITY); JsonAssert.assertEquals(view.toJson(false), viewAfterRemove.toJson(false)); }
@Test public void shouldThrowExceptionOnRemovalOfNullGroups() { final View view = new View.Builder() .edge(TestGroups.EDGE) .build(); final Exception exception = assertThrows(IllegalArgumentException.class, () -> ViewUtil.removeGroups(view, null)); assertEquals("Specified group(s) to remove is null", exception.getMessage()); }
@Test public void shouldThrowExceptionOnWhenRemovingGroupFromNullView() { final Exception exception = assertThrows(IllegalArgumentException.class, () -> ViewUtil.removeGroups(null, TestGroups.EDGE)); assertEquals("View cannot be null", exception.getMessage()); }