### Question:
VirtualMachineDestroyed implements Predicate<VirtualMachine> { public boolean apply(VirtualMachine virtualMachine) { logger.trace("looking for state on virtualMachine %s", checkNotNull(virtualMachine, "virtualMachine")); virtualMachine = refresh(virtualMachine); if (virtualMachine == null) return true; logger.trace("%s: looking for virtualMachine state %s: currently: %s", virtualMachine.getId(), State.DESTROYED, virtualMachine.getState()); return virtualMachine.getState() == State.DESTROYED; } @Inject  VirtualMachineDestroyed(CloudStackApi client); boolean apply(VirtualMachine virtualMachine);  }### Answer:
@Test public void testIsDestroyed() { VirtualMachine virtualMachine = VirtualMachine.builder(). id("229").state(VirtualMachine.State.DESTROYED).build(); expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine); replay(client, virtualMachineClient); assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine)); verify(client, virtualMachineClient); }
@Test public void testStillRunning() { VirtualMachine virtualMachine = VirtualMachine.builder(). id("229").state(VirtualMachine.State.RUNNING).build(); expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine); replay(client, virtualMachineClient); assertFalse(new VirtualMachineDestroyed(client).apply(virtualMachine)); verify(client, virtualMachineClient); }