TruncatingStringModel implements IModel<String> { @Override public String getObject() { final String object = model.getObject(); if (object == null) { return null; } else if (object.length() <= maxLength) { return object; } else { return object.substring(0, truncatePoint) + ELLIPSIS; } } TruncatingStringModel(IModel<String> model, int maxLength, int truncatePoint); @Override String getObject();  }
@Test public void testGetObjectFits() { innerModel.setObject("abcd"); assertEquals("abcd", instance.getObject()); innerModel.setObject("abcde"); assertEquals("abcde", instance.getObject()); }
@Test public void testGetObjectTruncated() { innerModel.setObject("abcdef"); assertEquals("ab\u2026", instance.getObject()); }
@Test public void testGetObjectNull() { innerModel.setObject(null); assertNull(instance.getObject()); }