### Question:
DocumentConverter extends AbstractConverter<Document> { @Override public <G> G convert(Type targetType, Object sourceValue) { if (sourceValue == null) { return null; } if (sourceValue instanceof Document) { return convertFromType(targetType, sourceValue); } else { return super.convert(targetType, sourceValue); } }  @Override G convert(Type targetType, Object sourceValue); @Override Document convertToType(Type targetType, Object sourceValue);  }### Answer:
@Test void convertToDocumentReference() { assertEquals(this.documentReference, documentConverter.convert(DocumentReference.class, document)); }
@Test void convertFromXWikiDocument() { Document convertedDocument = documentConverter.convert(Document.class, this.xWikiDocument); assertSame(this.xWikiDocument, convertedDocument.getDocument()); }
@Test void convertFromUnsupportedType() { ConversionException conversionException = assertThrows(ConversionException.class, () -> { documentConverter.convert(Document.class, this.documentReference); }); assertEquals("Unsupported source type [class org.xwiki.model.reference.DocumentReference]", conversionException.getMessage()); }
@Test void convertToUnsupportedType() { ConversionException conversionException = assertThrows(ConversionException.class, () -> { documentConverter.convert(Integer.class, this.document); }); assertEquals("Unsupported target type [class java.lang.Integer]", conversionException.getMessage()); }