### Question:
DocumentFieldValueMarshaller extends AbstractFieldValueMarshaller<Document, DocumentData, DocumentFieldDefinition> { @Override public Document toRawValue(DocumentData documentData) { if (documentData == null) { return null; } if (documentData.getStatus().equals(DocumentStatus.STORED)) { return originalValue; } return toDocument(documentData, documentStorage); } @Inject  DocumentFieldValueMarshaller(UploadedDocumentStorage documentStorage); @Override Class<DocumentFieldDefinition> getSupportedField(); @Override Supplier<FieldValueMarshaller<Document, DocumentData, DocumentFieldDefinition>> newInstanceSupplier(); @Override DocumentData toFlatValue(); @Override Document toRawValue(DocumentData documentData); static final String SERVER_TEMPLATE_ID; }### Answer:
@Test public void testNullFlatValue2Document() { marshaller.init(null, field, form, context); Document doc = marshaller.toRawValue(null); assertNull("Document must be null!", doc); }
@Test public void testNewFlatValue2Document() { marshaller.init(null, field, form, context); DocumentData data = new DocumentData(DOCUMENT_ID, 1024, null); data.setContentId("content"); Document doc = marshaller.toRawValue(data); verify(documentStorage).getContent(anyString()); verify(documentStorage).removeContent(anyString()); assertNotNull("Document cannot be null!", doc); assertEquals("Names are not equal", data.getFileName(), doc.getName()); assertEquals("Sizes are not equal", data.getSize(), doc.getSize()); }
@Test public void testExistingFlatValue2Document() { Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink"); marshaller.init(doc, field, form, context); DocumentData data = new DocumentData(doc.getName(), doc.getSize(), doc.getLink()); data.setStatus(DocumentStatus.STORED); Document rawDoc = marshaller.toRawValue(data); assertEquals("Documents must be equal!", doc, rawDoc); verify(documentStorage, never()).getContent(anyString()); verify(documentStorage, never()).removeContent(anyString()); }