IconRenderer extends ComponentRenderer<Component, ITEM> { @Override public Component createComponent(ITEM item) { Component icon = iconGenerator.apply(item); if (icon == null) { throw new IllegalStateException(String.format( "Got 'null' as an icon for the item '%s'. " + "Icon generator instance may not return 'null' values", 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())); } IconComponent component = new IconComponent(); component.add(icon); component.add(new IconComponent(text)); return component; } IconRenderer(
            SerializableFunction<ITEM, ? extends Component> iconGenerator);  IconRenderer(
            SerializableFunction<ITEM, ? extends Component> iconGenerator,
            ItemLabelGenerator<ITEM> itemLabelGenerator); @Override Component createComponent(ITEM item);  }
@Test(expected = IllegalStateException.class) public void dontAllowNullInLabelGenerator() { IconRenderer<Object> renderer = new IconRenderer<>( obj -> new TestComponent(), obj -> null); renderer.createComponent(new Object()); }
@Test(expected = IllegalStateException.class) public void dontAllowNullInIconGenerator() { IconRenderer<Object> renderer = new IconRenderer<>(obj -> null, obj -> ""); renderer.createComponent(new Object()); }