### Question:
StringListCellRenderer implements ListCellRenderer<E> { @Override public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setText(representer.apply(value)); return label; } StringListCellRenderer(Function<E, String> representer); @Override Component getListCellRendererComponent(JList<? extends E> list,
                                                E value,
                                                int index,
                                                boolean isSelected,
                                                boolean cellHasFocus);  }### Answer:
@Test public void returnsNullForNullValue() { Component result = renderer.getListCellRendererComponent(list, null, 0, true, true); assertThat(result, is(instanceOf(JLabel.class))); JLabel labelResult = (JLabel) result; assertThat(labelResult.getText(), is(equalTo(""))); }
@Test public void returnsLabelWithNameAsText() { Vehicle vehicle = new Vehicle("VehicleName"); TCSObjectReference<Vehicle> vehicleReference = vehicle.getReference(); Component result = renderer.getListCellRendererComponent(list, vehicleReference, 0, true, true); assertThat(result, is(instanceOf(JLabel.class))); JLabel labelResult = (JLabel) result; assertThat(labelResult.getText(), is(equalTo("VehicleName"))); }