UrlFromStringModel implements IModel<URL> { @Override public void setObject(URL object) { if (object == null) { model.setObject(null); } else { final String scheme = object.getProtocol().toLowerCase(); if (scheme.equals("http") || scheme.equals("https")) { model.setObject(object.toString()); } else { try { model.setObject(new File(object.toURI()).getAbsolutePath()); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } } } } UrlFromStringModel(IModel<String> model); @Override URL getObject(); @Override void setObject(URL object); @Override void detach();  }
@Test public void testSetObject() throws MalformedURLException { final Model<String> innerModel = Model.of(""); final UrlFromStringModel instance = new UrlFromStringModel(innerModel); instance.setObject(null); assertNull(innerModel.getObject()); instance.setObject(new URL("file:/my/file/location")); assertEquals("/my/file/location", innerModel.getObject()); instance.setObject(new URL("http: assertEquals("http: }