### Question:
InstanceUtils { public static Optional<Double> getClassValue(final Instance instance, final DatasetSchema schema) { return schema.getTargetIndex() .map(instance::getValue); } private  InstanceUtils(); static Optional<Double> getClassValue(final Instance instance, final DatasetSchema schema); static boolean isMissingClass(final Instance instance, final DatasetSchema schema); static boolean isMissing(final Instance instance, final int index);  }### Answer:
@Test public void testGetClassValue() { final double[] fieldValues = fieldValues(index -> index * 10.0); final MockInstance instance = new MockInstance(fieldValues); final Optional<Integer> targetIndex = this.schema.getTargetIndex(); assertThat(targetIndex) .as("The dataset target variable index") .isPresent(); assertThat(InstanceUtils.getClassValue(instance, this.schema)) .as("The class value for the instance") .hasValue(targetIndex.get() * 10.0); }
@Test public final void testGetClassValueNoTarget() { final double[] fieldValues = fieldValues(index -> index * 10.0); final MockInstance instance = new MockInstance(fieldValues); final DatasetSchema noTargetSchema = new DatasetSchema(this.schema.getFieldSchemas()); assertThat(InstanceUtils.getClassValue(instance, noTargetSchema)) .as("The class value for the instance, where the dataset has no schema") .isNotPresent(); }