### Question:
DataSourceHolderResourceConverter extends ResourceConverterImpl<ResourceType, ClientType> { @Override protected ResourceType genericFieldsToServer(ClientType clientObject, ResourceType resultToUpdate, ToServerConversionOptions options) throws IllegalParameterValueException, MandatoryParameterNotFoundException { resultToUpdate = super.genericFieldsToServer(clientObject, resultToUpdate, options); ResourceReference dataSourceReference = resourceReferenceConverterProvider .getConverterForType(ClientReferenceableDataSource.class) .toServer(clientObject.getDataSource(), getDataSourceFromResource(resultToUpdate), options); setDataSourceToResource(dataSourceReference, resultToUpdate); return resultToUpdate; }    }### Answer:
@Test public void genericFieldsToServer_DataSource_nullIsChangedToReference() throws Exception { final ClientQuery clientObject = new ClientQuery(); clientObject.setLabel("m"); final ClientAwsDataSource clientDataSource = new ClientAwsDataSource(); clientObject.setDataSource(clientDataSource); clientObject.setUri(TEST_RESORUCE_URI); serverObject.setDataSource((ResourceReference)null); testResourceReference.setReference(TEST_REFERENCE_URI); when(resourceReferenceConverter.toServer(clientDataSource, null, null)).thenReturn(testResourceReference); final Resource result = converter.genericFieldsToServer(clientObject, serverObject, null); assertSame(result, serverObject); assertSame(((Query)result).getDataSource(), testResourceReference); assertEquals(result.getURIString(), TEST_RESORUCE_URI); }
@Test public void genericFieldsToServer_DataSource_referenceIsChangedToNull() throws Exception { final ClientQuery clientObject = new ClientQuery(); clientObject.setLabel("m"); final ClientAwsDataSource clientDataSource = new ClientAwsDataSource(); testResourceReference.setReference("/test/resoruce/uri"); serverObject.setDataSource(testResourceReference); when(resourceReferenceConverter.toServer(clientDataSource, null)).thenReturn(testResourceReference); final Resource result = converter.genericFieldsToServer(clientObject, serverObject, null); assertSame(result, serverObject); assertNull(((Query) result).getDataSource()); }
@Test public void genericFieldsToServer_DataSource_Null() throws Exception { final ClientQuery clientObject = new ClientQuery(); clientObject.setLabel("m"); final ClientAwsDataSource clientDataSource = new ClientAwsDataSource(); testResourceReference.setReference("/test/resoruce/uri"); serverObject.setDataSource((ResourceReference)null); when(resourceReferenceConverter.toServer(clientDataSource, null)).thenReturn(testResourceReference); final Resource result = converter.genericFieldsToServer(clientObject, serverObject, null); assertSame(result, serverObject); assertNull(((Query) result).getDataSource()); }
@Test public void genericFieldsToServer_newInstanceOfServerObjectIsCreated() throws MandatoryParameterNotFoundException, IllegalParameterValueException { final ClientQuery clientObject = new ClientQuery(); clientObject.setLabel("m"); final ClientAwsDataSource clientDataSource = new ClientAwsDataSource(); clientObject.setDataSource(clientDataSource); testResourceReference.setReference("/test/resoruce/uri"); when(resourceReferenceConverter.toServer(clientDataSource, null, null)).thenReturn(testResourceReference); final QueryImpl newServerObject = new QueryImpl(); when(converter.getNewResourceInstance()).thenReturn(newServerObject); final Resource resource = converter.genericFieldsToServer(clientObject, null, null); assertSame(resource, newServerObject); assertSame(((QueryImpl)resource).getDataSource(), testResourceReference); }