@Test
public void testShrinkToFit() {

  JLabel testLabel = new JLabel("Test");
  FontMetrics testMetrics = testLabel.getFontMetrics(AdtUiUtils.DEFAULT_FONT);
  String testString = StringUtil.repeat("A", 100);
  int stringWidth = testMetrics.stringWidth(testString);
  int ellipsisWidth = testMetrics.stringWidth(ELLIPSIS);
  int perCharacterWidth = testMetrics.stringWidth("A");
  // Enough space to render the whole string so no truncation occurs
  assertEquals(testString, AdtUiUtils.shrinkToFit(testString, testMetrics, stringWidth));
  // Not enough space for ellipsis so an empty string should be returned
  assertEquals("", AdtUiUtils.shrinkToFit(testString, testMetrics, ellipsisWidth - 1));
  // Just enough space for ellipsis, but we should still return an empty string (since "..." on
  // its own is useless)
  assertEquals("", AdtUiUtils.shrinkToFit(testString, testMetrics, ellipsisWidth));
  for (int i = 5; i < 80; ++i) {
    int spaceAvailable = i * perCharacterWidth;
    String shrunk = AdtUiUtils.shrinkToFit(testString, s -> testMetrics.stringWidth(s) <= spaceAvailable + ellipsisWidth);
    assertEquals(StringUtil.repeat("A", i) + "...", shrunk);
  }
}