### Question:
TimeFractionDeltaEnricher extends AbstractTypeTransformingEnricher<T,Double> { @Override public void onEvent(SensorEvent<T> event) { onEvent(event, event.getTimestamp()); } TimeFractionDeltaEnricher();  TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, TimeUnit origUnits);  TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, long nanosPerOrigUnit); @Override void onEvent(SensorEvent<T> event); void onEvent(SensorEvent<T> event, long eventTimestamp);  }### Answer:
@Test public void testCalculatesFractions() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, TimeUnit.MILLISECONDS); producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 0d); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 100, 1002000L)); assertEquals(producer.getAttribute(fractionSensor), 0.1d, PRECISION); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 300, 1003000L)); assertEquals(producer.getAttribute(fractionSensor), 0.2d, PRECISION); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 2300, 1004000L)); assertEquals(producer.getAttribute(fractionSensor), 2d, PRECISION); }
@Test public void testConvertsTimeUnits() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, TimeUnit.MICROSECONDS); producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 1000000, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 1d); }
@Test public void testConverts100NanosTimeBlocks() { TimeFractionDeltaEnricher<Integer> enricher = new TimeFractionDeltaEnricher<Integer>(producer, intSensor, fractionSensor, 100); producer.enrichers().add(enricher); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 10000000, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 1d); }