### Question:
FileResourceConverter extends ResourceConverterImpl<FileResource, ClientFile> { @Override protected ClientFile resourceSpecificFieldsToClient(ClientFile client, FileResource serverObject, ToClientConversionOptions options) { String type; if (serverObject.isReference()){ FileResource referenced = (FileResource)repositoryService.getResource(null, serverObject.getReferenceURI()); type = referenced.getFileType(); } else { type = serverObject.getFileType(); } ClientFile.FileType clientFileType; try{ clientFileType = ClientFile.FileType.valueOf(type); }catch (Exception e){ clientFileType = ClientFile.FileType.unspecified; } client.setType(clientFileType); return client; }    }### Answer:
@Test public void resourceSpecificFieldsToClient(){ final String expectedFileType = FileResource.TYPE_JRXML; final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(); serverObject.setFileType(expectedFileType); serverObject.setData(data); final ClientFile result = converter.resourceSpecificFieldsToClient(clientObject, serverObject, null); assertNotNull(result); assertEquals(result.getType().name(), expectedFileType); assertEquals(result.getContent(), null); }
@Test public void resourceSpecificFieldsToClient_reference(){ final String expectedFileType = FileResource.TYPE_JRXML; final String referencedUri = "/test"; final ClientFile clientObject = new ClientFile(); final FileResource serverObject = new FileResourceImpl(), referenced = new FileResourceImpl(); referenced.setFileType(expectedFileType); serverObject.setData(data); serverObject.setReferenceURI(referencedUri); when(repositoryService.getResource(nullable(ExecutionContext.class), eq(referencedUri))).thenReturn(referenced); final ClientFile result = converter.resourceSpecificFieldsToClient(clientObject, serverObject, null); assertNotNull(result); assertEquals(result.getType().name(), expectedFileType); }
@Test public void resourceSpecificFieldsToClient_unsupportedFileTypeBecomesUnspecified(){ final FileResourceImpl serverObject = new FileResourceImpl(); serverObject.setFileType("someNotSupportedFileType"); final ClientFile clientFile = converter.resourceSpecificFieldsToClient(new ClientFile(), serverObject, null); assertSame(clientFile.getType(), ClientFile.FileType.unspecified); }