UrlFromStringModel implements IModel<URL> { @Override public URL getObject() { final String object = model.getObject(); if (object == null) { return null; } else { try { if (URL_PATTERN.matcher(object).matches()) { return new URL(object); } else { return new File(object).toURI().toURL(); } } catch (MalformedURLException ex) { throw new RuntimeException(ex); } } } UrlFromStringModel(IModel<String> model); @Override URL getObject(); @Override void setObject(URL object); @Override void detach();  }
@Test public void testGetObject() throws MalformedURLException { final Model<String> innerModel = Model.of(""); final UrlFromStringModel instance = new UrlFromStringModel(innerModel); innerModel.setObject(null); assertNull(instance.getObject()); innerModel.setObject("/my/file/location"); assertEquals(new URL("file:/my/file/location"), instance.getObject()); innerModel.setObject("http: assertEquals(new URL("http: innerModel.setObject("https: assertEquals(new URL("https: }