### Question:
FileResourceConverter extends ResourceConverterImpl<FileResource, ClientFile> { @Override protected FileResource resourceSpecificFieldsToServer(ClientFile clientObject, FileResource resultToUpdate, List<Exception> exceptions, ToServerConversionOptions options) throws IllegalParameterValueException { if(resultToUpdate.getFileType() != null || resultToUpdate.isReference()){ String type; if (resultToUpdate.isReference()){ FileResource referenced = (FileResource)repositoryService.getResource(null, resultToUpdate.getReferenceURI()); type = referenced.getFileType(); } else { type = resultToUpdate.getFileType(); } if (!type.equals(clientObject.getType().name())){ throw new IllegalParameterValueException("type", clientObject.getType().name()); } } if (!resultToUpdate.isReference()){ resultToUpdate.setFileType(clientObject.getType().name()); } if (clientObject.getContent() != null && !"".equals(clientObject.getContent())) { try { resultToUpdate.setData(DatatypeConverter.parseBase64Binary(clientObject.getContent())); } catch (IllegalArgumentException e) { throw new IllegalParameterValueException("content", ""); } resultToUpdate.setReferenceURI(null); resultToUpdate.setFileType(clientObject.getType().name()); } return resultToUpdate; }    }### Answer:
@Test public void resourceSpecificFieldsToServer() throws Exception{ final String expectedFileType = FileResource.TYPE_JRXML; final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(); clientObject.setType(ClientFile.FileType.jrxml); clientObject.setContent(encoded); final FileResource result = converter.resourceSpecificFieldsToServer(clientObject, serverObject, new ArrayList<Exception>(), null); assertNotNull(result); assertEquals(result.getFileType(), expectedFileType); assertEquals(result.getData(), data); }
@Test public void resourceSpecificFieldsToServer_reference_toFullResource() throws Exception{ final String expectedFileType = FileResource.TYPE_JRXML; final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(), referenced = new FileResourceImpl(); serverObject.setReferenceURI("aff"); referenced.setFileType(expectedFileType); clientObject.setType(ClientFile.FileType.jrxml); clientObject.setContent(encoded); when(repositoryService.getResource(nullable(ExecutionContext.class), anyString())).thenReturn(referenced); final FileResource result = converter.resourceSpecificFieldsToServer(clientObject, serverObject, new ArrayList<Exception>(), null); assertNotNull(result); assertNotNull(result.getFileType()); assertEquals(result.getData(), data); }
@Test(expectedExceptions = {IllegalParameterValueException.class}) public void resourceSpecificFieldsToServer_reference_TypeDifferent() throws Exception{ final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(), referenced = new FileResourceImpl(); serverObject.setReferenceURI("aff"); referenced.setFileType(FileResource.TYPE_ACCESS_GRANT_SCHEMA); clientObject.setType(ClientFile.FileType.jrxml); clientObject.setContent(encoded); when(repositoryService.getResource(nullable(ExecutionContext.class), anyString())).thenReturn(referenced); final FileResource result = converter.resourceSpecificFieldsToServer(clientObject, serverObject, new ArrayList<Exception>(), null); }
@Test(expectedExceptions = {IllegalParameterValueException.class}) public void resourceSpecificFieldsToServer_TypeDifferent() throws Exception{ final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(); serverObject.setFileType(FileResource.TYPE_ACCESS_GRANT_SCHEMA); clientObject.setType(ClientFile.FileType.jrxml); clientObject.setContent(encoded); final FileResource result = converter.resourceSpecificFieldsToServer(clientObject, serverObject, new ArrayList<Exception>(), null); }