ClassWrapperRenderer implements TableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String abbreviatePackage = ""; if (value != null) { final ClassWrapper classWrapper = (ClassWrapper) value; final String className = Optional.ofNullable(classWrapper.getClassName()).orElse(""); abbreviatePackage = abbreviatePackageUsingMappings(className, replacements); int availableWidth = table.getColumnModel().getColumn(column).getWidth(); availableWidth -= table.getIntercellSpacing().getWidth(); if (label.getBorder() != null) { Insets borderInsets = label.getBorder().getBorderInsets(label); availableWidth -= (borderInsets.left + borderInsets.right); } FontMetrics fm = label.getFontMetrics(label.getFont()); abbreviatePackage = abbreviatePackagesToSingleLetter(abbreviatePackage, availableWidth, fm); while (fm.stringWidth(abbreviatePackage) > availableWidth && abbreviatePackage.length() > 0) { abbreviatePackage = abbreviatePackage.substring(1); } } label.setText(abbreviatePackage); return label; } ClassWrapperRenderer(); @Override Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column); String abbreviatePackagesToSingleLetter(String abbreviatePackage, int availableWidth, FontMetrics fm); void reloadConfiguration(String propertyConfiguration);  }
@Test public void testIsNullSafe() throws Exception { underTest.getTableCellRendererComponent(Mockito.mock(JTable.class), null, false, false, 0, 0); }