### Question:
ResourceHashModel implements TemplateHashModelEx, TemplateScalarModel, ResourceTemplate { @Override public String getAsString() throws TemplateModelException { if (resource.getURI() == null) { return INVALID_URL; } else { return resource.getURI(); } } ResourceHashModel(Resource resource); @Override int size(); @Override TemplateCollectionModel keys(); @Override TemplateCollectionModel values(); @Override TemplateModel get(String s); @Override boolean isEmpty(); @Override String getAsString(); @Override Resource getResource(); final static String INVALID_URL; }### Answer:
@Test public void testAsStringWithUri() throws TemplateModelException { assertEquals("Unexpected string value", testUri, resourceHashModel.getAsString()); }
@Test public void testAsStringWithBNode() throws TemplateModelException { Resource resource = ModelFactory.createDefaultModel().createResource(); ResourceHashModel resourceHashModel = new ResourceHashModel(resource); assertEquals("Unexpected URI", ResourceHashModel.INVALID_URL, resourceHashModel.getAsString()); }