AbstractAggregator implements Aggregator { public static Number downCast(long value) { Number retVal; if (value <= Integer.MAX_VALUE && value >= Integer.MIN_VALUE) { retVal = Integer.valueOf((int) value); } else { retVal = value; } return retVal; }  static Number downCast(long value); static Number downCast(double value);  }
@Test public void downcastShouldReturnIntegerWhenValueIsAnIntegerAndFitsWithinTheIntegerRange() { int randomInteger = random.nextInt(); Number integerResult = AbstractAggregator.downCast(randomInteger); assertThat(integerResult).isInstanceOf(Number.class); assertThat(integerResult).isInstanceOf(Integer.class); }
@Test public void downcastShouldReturnLongWhenValueIsAnIntegerButDoesNotFitsWithinTheIntegerRange() { long randomLong = random.nextLong(); Number longResult = AbstractAggregator.downCast(randomLong); assertThat(longResult).isInstanceOf(Number.class); assertThat(longResult).isInstanceOf(Long.class); }
@Test public void downcastShouldReturnFloatWhenValueIsNotAnIntegerAndFitsWithinTheFloatRange() { float randomFloat = random.nextFloat(); Number floatResult = AbstractAggregator.downCast(randomFloat); assertThat(floatResult).isInstanceOf(Number.class); assertThat(floatResult).isInstanceOf(Float.class); }
@Test public void downcastShouldReturnDoubleWhenValueIsNotAnIntegerAndDoesNotFitsWithinTheFloatRange() { double randomDouble = Float.MIN_VALUE - random.nextDouble(); Number doubleResult = AbstractAggregator.downCast(randomDouble); assertThat(doubleResult).isInstanceOf(Number.class); assertThat(doubleResult).isInstanceOf(Double.class); }