### Question:
DataSetHelper { public abstract <T extends Serializable, S extends Individual<T, S>> S replace(Serializable from, T to, Class<? extends S> clazz); DataSetHelper(); abstract S replace(Serializable from, T to, Class<? extends S> clazz); abstract ManagedIndividual manage(ManagedIndividualId id); abstract T self(); abstract T relative(URI path); abstract IndividualHelper externalIndividual(URI uri); abstract IndividualHelper managedIndividual(Name<?> name, String managerId); abstract IndividualHelper relativeIndividual(Name<?> name, String managerId, URI path); abstract IndividualHelper localIndividual(Name<?> name); static final URI SELF; }### Answer:
@Test public void testReplacesSelf() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> original = dataSet.individualOfId(SELF); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( original.id(), managedIndividualId("other","managerId"), ManagedIndividual.class); assertIsProperlyRenamed(dataSet, original, individual, "self"); }
@Test public void testReplacesNew() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> original = dataSet.individualOfId(NEW); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( original.id(), managedIndividualId("other","managerId"), ManagedIndividual.class); assertIsProperlyRenamed(dataSet, original, individual, "new"); }
@Test public void testReplacesManagedIndividual() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> original = dataSet.individualOfId(MANAGED_INDIVIDUAL_ID); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( original.id(), managedIndividualId("other","managerId"), ManagedIndividual.class); assertIsProperlyRenamed(dataSet, original, individual, "managed"); }
@Test public void testReplacesRelativeIndividual() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> original = dataSet.individualOfId(relativeIndividualId(RESOURCE_NAME.id(), MANAGER_ID, RELATIVE_PATH)); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( original.id(), managedIndividualId("other","managerId"), ManagedIndividual.class); assertIsProperlyRenamed(dataSet, original, individual, "relative"); }
@Test public void testReplacesBlankNode() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> original = dataSet.individualOfId(BLANK_NODE); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( original.id(), managedIndividualId("other","managerId"), ManagedIndividual.class); assertIsProperlyRenamed(dataSet, original, individual, "bnode"); }
@Test public void testDoesNotReplacesItself() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( managedIndividualId("other","managerId"), managedIndividualId("other","managerId"), ManagedIndividual.class); assertThat(individual,nullValue()); }
@Test public void testDoesNotReplacesUnknown() throws Exception { DataSet dataSet = exampleDataSet(); Individual<?,?> individual= DataSetUtils. newHelper(dataSet). replace( managedIndividualId("other","managerId"), managedIndividualId("another","managerId"), ManagedIndividual.class); assertThat(individual,nullValue()); }