### Question:
RateTransform extends Transform { @Override public Object process(Object value) { Long time = System.currentTimeMillis(); if (this.lastValue == null) { this.lastUpdate = time; this.lastValue = value; return null; } if (!(value instanceof Number)) { throw new IllegalArgumentException(String.format("Rate requested, but value '%s' of type '%s' is not a number", value.toString(),value.getClass().getName())); } double diff = ((Number) value).doubleValue() - ((Number) this.lastValue).doubleValue(); double timeChangeInSeconds = ((double)(time - this.lastUpdate)) / 1000.0; double rate; if(timeChangeInSeconds == 0.0) rate = Double.NaN; else { rate = diff / timeChangeInSeconds; if(Math.abs(rate) < EPS) { rate = 0.0; } } if (Double.isNaN(rate) || rate == Double.POSITIVE_INFINITY || rate == Double.NEGATIVE_INFINITY) { log.warn("Overflow in rate calculation: val=%f, last val=%f; time=%tc, last time=%tc", ((Number) value).doubleValue(), ((Number) this.lastValue).doubleValue(), time, this.lastUpdate); this.lastUpdate = time; this.lastValue = value; return null; } this.lastUpdate = time; this.lastValue = value; return rate; }  @Override Object process(Object value);  }### Answer:
@Test(groups = "slow") public void integerTypeTest() { RateTransform rt = new RateTransform(); assertEquals(null, rt.process(new Integer(12))); sleep(10); assertEquals(Double.class, rt.process(new Integer(2)).getClass()); }
@Test(groups = "slow", expectedExceptions = IllegalArgumentException.class) public void nullTypeTest() { RateTransform rt = new RateTransform(); assertEquals(null, rt.process(new Double(12))); sleep(10); rt.process(new Double("foo")); }
@Test(groups = "slow") public void rateTest1() { RateTransform rt = new RateTransform(); assertEquals(null, rt.process(new Double(12))); sleep(10); assertEquals(0.0, rt.process(new Double(12))); sleep(10); assertTrue((Double) rt.process(new Double(0.0)) < 0.0); sleep(10); assertTrue((Double) rt.process(new Double(10.0)) > 0.0); }
@Test(groups = "fast") public void nullStartTest() { RateTransform rt = new RateTransform(); assertEquals(null, rt.process(new Double(12))); }
@Test(groups = "slow") public void objectTypeTest() { RateTransform rt = new RateTransform(); assertEquals(null, rt.process(new Double(12))); sleep(10); assertEquals(Double.class, rt.process(new Double(12)).getClass()); }