private void produceTableValueContainingNull(TreeTable tree) { tree.select(ROOT_0); assertThat((Set<?>) tree.getValue(), contains(ROOT_0)); focusParent(tree, ROOT_0); // using a random rowKey, doesn't matter here }
@Test public void clickListenerDoesntFailWhenValueContainsNull() throws Exception { // GIVEN final TreeTable tree = mock(TreeTable.class); final ArgumentCaptor<ItemClickEvent.ItemClickListener> itemClickListener = ArgumentCaptor.forClass(ItemClickEvent.ItemClickListener.class); setUp(new TreeViewImpl() { @Override protected TreeTable createTable(Container container) { return tree; } }); verify(tree).addItemClickListener(itemClickListener.capture()); // we already proved above a null-only set could occur as value before Set<Object> nullOnlySelection = new HashSet<>(); nullOnlySelection.add(null); doReturn(nullOnlySelection).when(tree).getValue(); // WHEN/THEN assertThat(new Execution() { @Override public void evaluate() throws Exception { // manually clicking sth else again (i.e. where our NPE originated from) itemClickListener.getValue().itemClick(new ItemClickEvent(tree, null, "foo", null, mock(MouseEventDetails.class))); } }, throwsNothing()); }
/** * Should this test start to fail right after focusParent, returning null selection instead of a Set containing null, * then we'd consider it a Vaadin fix and remove the attached workaround in ListViewImpl. */ @Test public void proveVaadinTableValueCanBeASetContainingNull() throws Exception { // when an itemId is selected and we process e.g. an itemClick, we want to unselect it // make sure this doesn't fail if value ends up being a set containing null // GIVEN TreeTable tree = new TreeTable(null, buildContainer()); tree.setSelectable(true); tree.setMultiSelect(true); assertThat(tree.getValue(), anyOf(nullValue(), instanceOf(Set.class))); // WHEN produceTableValueContainingNull(tree); // THEN assertThat((Set<?>) tree.getValue(), contains((Object) null)); }