String snapshotDesc = "snapDesc";
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
IMachine machine = createMock(IMachine.class);
IVirtualBox vBox = createMock(IVirtualBox.class);
ISession session = createMock(ISession.class);
IConsole console = createNiceMock(IConsole.class);
IProgress progress = createNiceMock(IProgress.class);
ISnapshot snapshot = createNiceMock(ISnapshot.class);
expect(machine.getCurrentSnapshot()).andReturn(snapshot).anyTimes();
expect(machine.getState()).andReturn(MachineState.PoweredOff).anyTimes();
expect(manager.openMachineSession(machine)).andReturn(session);
expect(session.getConsole()).andReturn(console);
expect(console.takeSnapshot(snapshotName, snapshotDesc)).andReturn(
progress);
expect(progress.getCompleted()).andReturn(true);
session.unlockMachine();
replay(manager, machine, vBox, session, console, progress);
new TakeSnapshotIfNotAlreadyAttached(Suppliers.ofInstance(manager), snapshotName, snapshotDesc, Logger.CONSOLE)
.apply(machine);