### Question:
XClassRelativeStringEntityReferenceResolver extends AbstractStringEntityReferenceResolver { @Override public EntityReference resolve(String entityReferenceRepresentation, EntityType type, Object... parameters) { EntityReference explicitReference = new EntityReference("XWiki", EntityType.SPACE); if (parameters.length > 0 && (parameters[0] instanceof EntityReference)) { EntityReference extractedPageReference = ((EntityReference) parameters[0]).extractReference(EntityType.DOCUMENT); if (extractedPageReference != null) { explicitReference = new EntityReference(extractedPageReference.getName(), EntityType.DOCUMENT, explicitReference); } } return super.resolve(entityReferenceRepresentation, type, explicitReference); }  @Override EntityReference resolve(String entityReferenceRepresentation, EntityType type, Object... parameters);  }### Answer:
@Test public void testResolve() { EntityReference reference = this.resolver.resolve("page", EntityType.DOCUMENT); Assert.assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName()); Assert.assertEquals("XWiki", reference.extractReference(EntityType.SPACE).getName()); Assert.assertNull(reference.extractReference(EntityType.WIKI)); }
@Test public void testResolveWhenExplicitParameterAndNoPageInStringRepresentation() { EntityReference reference = this.resolver.resolve("", EntityType.DOCUMENT, new DocumentReference("dummy", "dummy", "page")); Assert.assertEquals("page", reference.extractReference(EntityType.DOCUMENT).getName()); Assert.assertEquals("XWiki", reference.extractReference(EntityType.SPACE).getName()); Assert.assertNull(reference.extractReference(EntityType.WIKI)); }
@Test public void testResolveWhenNoPageReferenceSpecified() { try { this.resolver.resolve("", EntityType.DOCUMENT); Assert.fail("Should have thrown an exception here"); } catch (IllegalArgumentException expected) { Assert.assertEquals("A Reference to a page must be passed as a parameter when the string to resolve " + "doesn't specify a page", expected.getMessage()); } }