@Test
public void testNexChargeTime() {

    final Queue<Double> vmTimes = new LinkedList<>(Arrays.asList(0d, 30d * MINUTE, 100d * MINUTE));
    VMex vmMock = new VMex("TestVM", broker.getId(), VM_MIPS, 1, VM_RAM, VM_BW, VM_SIZE, "Test",
            new CloudletSchedulerTimeShared()) {
        @Override
        protected double getCurrentTime() {
            return vmTimes.poll();
        }
    };
    final Queue<Double> policyTimes = new LinkedList<>(Arrays.asList(35d * MINUTE + 1, 60d * MINUTE + 1,
            91d * MINUTE + 1, 101d * MINUTE + 1));
    IVmBillingPolicy policyMock = new EC2OnDemandPolicy(ImmutableMap.<Pair<String, String>, BigDecimal> of()) {
        @Override
        protected double getCurrentTime() {
            return policyTimes.poll();
        }
    };
    // Asks when the VM is still in init phase
    assertEquals(-1d, policyMock.nexChargeTime(vmMock), 0.01);
    // Sets the RUNNING status 30min after start
    vmMock.setStatus(VMStatus.RUNNING);
    // Asks 35 mins after start - the VM is now running
    assertEquals(90d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01);
    // Asks 60 mins after start - the VM is now running
    assertEquals(90d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01);
    // Asks 91 mins after start - the VM is now running
    assertEquals(150d * MINUTE, policyMock.nexChargeTime(vmMock), 0.01);
    // Sets the TERMINATED status 100min after start
    vmMock.setStatus(VMStatus.TERMINATED);
    // Asks 101 mins after start - the VM is now stopped
    assertEquals(-1d, policyMock.nexChargeTime(vmMock), 0.01);
}