@Override
    public long nextBackOffMillis() {
        // Make sure we have not gone over the maximum elapsed time.
        if (getElapsedTimeMillis() > maxElapsedTimeMillis) {
            return maxElapsedTimeMillis;
        }
        int randomizedInterval =
                getRandomValueFromInterval(randomizationFactor, Math.random(), currentIntervalMillis);
        incrementCurrentInterval();
        return randomizedInterval;
    }
@Test
    public void testBackOff() {
        int testInitialInterval = 500;
        double testRandomizationFactor = 0.1;
        double testMultiplier = 2.0;
        int testMaxInterval = 5000;
        int testMaxElapsedTime = 900000;

        ExponentialBackOff backOffPolicy =
                new ExponentialBackOff.Builder()
                        .setInitialIntervalMillis(testInitialInterval)
                        .setRandomizationFactor(testRandomizationFactor)
                        .setMultiplier(testMultiplier)
                        .setMaxIntervalMillis(testMaxInterval)
                        .setMaxElapsedTimeMillis(testMaxElapsedTime)
                        .build();
        int[] expectedResults = {500, 1000, 2000, 4000, 5000, 5000, 5000, 5000, 5000, 5000};
        for (int expected : expectedResults) {
            assertEquals(expected, backOffPolicy.getCurrentIntervalMillis());
            // Assert that the next back off falls in the expected range.
            int minInterval = (int) (expected - (testRandomizationFactor * expected));
            int maxInterval = (int) (expected + (testRandomizationFactor * expected));
            long actualInterval = backOffPolicy.nextBackOffMillis();
            assertTrue(minInterval <= actualInterval && actualInterval <= maxInterval);
        }
    }