TextRenderer extends ComponentRenderer<Component, ITEM> { @Override public Component createComponent(ITEM item) { String text = itemLabelGenerator.apply(item); if (text == null) { throw new IllegalStateException(String.format( "Got 'null' as a label value for the item '%s'. " + "'%s' instance may not return 'null' values", item, ItemLabelGenerator.class.getSimpleName())); } return new TextRendererComponent(createElement(text)); } TextRenderer();  TextRenderer(ItemLabelGenerator<ITEM> itemLabelGenerator); @Override Component createComponent(ITEM item);  }
@Test(expected = IllegalStateException.class) public void dontAllowNullInLabelGenerator() { TextRenderer<Object> renderer = new TextRenderer<>(obj -> null); renderer.createComponent(new Object()); }