when(someMock.someMethod()).doAnswer(new Answer() { private int count = 0; public Object answer(InvocationOnMock invocation) { if (count++ == 1) return 1; return 2; } });
private Answer executeRequest(CacheBcfTopologyCommand cmd, int numRetries) { _latestTopology = cmd.getTopology(); return new Answer(cmd, true, "BCF topology cached"); }
/** * PlugNicAnswer: plug a network interface into a VM * @param cmd * @return */ public PlugNicAnswer execute(PlugNicCommand cmd) { Answer ans = plugNunplugNic(cmd.getNic(), cmd.getVmName(), true); return new PlugNicAnswer(cmd, ans.getResult(), ans.getDetails()); }
/** * UnPlugNicAnswer: remove a nic from a VM * @param cmd * @return */ public UnPlugNicAnswer execute(UnPlugNicCommand cmd) { Answer ans = plugNunplugNic(cmd.getNic(), cmd.getVmName(), false); return new UnPlugNicAnswer(cmd, ans.getResult(), ans.getDetails()); } }
@Override public Answer executeRequest(Command cmd) { if (cmd instanceof CheckNetworkCommand) { return new CheckNetworkAnswer((CheckNetworkCommand)cmd, true, null); } System.out.println("Received Command: " + cmd.toString()); Answer answer = new Answer(cmd, !_negative, "response"); System.out.println("Replying with: " + answer.toString()); return answer; }
@Override public Answer execute(final ReadyCommand command, final LibvirtComputingResource libvirtComputingResource) { return new ReadyAnswer(command); } }
public GetHostStatsAnswer(GetHostStatsCommand cmd, double cpuUtilization, double freeMemoryKBs, double totalMemoryKBs, double networkReadKBs, double networkWriteKBs, String entityType) { super(cmd); hostStats = new HostStatsEntry(); hostStats.setCpuUtilization(cpuUtilization); hostStats.setFreeMemoryKBs(freeMemoryKBs); hostStats.setTotalMemoryKBs(totalMemoryKBs); hostStats.setNetworkReadKBs(networkReadKBs); hostStats.setNetworkWriteKBs(networkWriteKBs); hostStats.setEntityType(entityType); }
@Override public MaintainAnswer execute(final MaintainCommand command, final NuageVspResource nuageVspResource) { return new MaintainAnswer(command); } }
@Override public StartupCommand[] initialize() { StartupExternalDhcpCommand cmd = new StartupExternalDhcpCommand(); cmd.setName(_name); cmd.setDataCenter(_zoneId); cmd.setPrivateIpAddress(_ip); cmd.setStorageIpAddress(""); cmd.setVersion(""); cmd.setGuid(_guid); return new StartupCommand[] {cmd}; }
static public PvlanSetupCommand createDhcpSetup(String op, URI uri, String networkTag, String dhcpName, String dhcpMac, String dhcpIp) { PvlanSetupCommand cmd = new PvlanSetupCommand(Type.DHCP, op, uri, networkTag); cmd.setDhcpName(dhcpName); cmd.setDhcpMac(dhcpMac); cmd.setDhcpIp(dhcpIp); return cmd; }
@Override public Answer execute(final GetVmDiskStatsCommand command, final CitrixResourceBase citrixResourceBase) { return new GetVmDiskStatsAnswer(command, null, null, null); } }
static public PvlanSetupCommand createVmSetup(String op, URI uri, String networkTag, String vmMac) { PvlanSetupCommand cmd = new PvlanSetupCommand(Type.VM, op, uri, networkTag); cmd.setVmMac(vmMac); return cmd; }
public PingTestCommand(String routerIp, String privateIp) { _routerIp = routerIp; _privateIp = privateIp; setWait(20); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof SyncDomainAnswer)) { return false; } SyncDomainAnswer that = (SyncDomainAnswer) o; return super.equals(that) && _success == that._success; }
VendorObject vo = mock(VendorObject.class, new Answer() { @Override public Object answer(InvocationOnMock invocation) { // 1. Check if method exists on RedirectToObject. // 2a. If it does, call the method with the args and return the // result. // 2b. If it does not, throw an exception to fail the unit test. } });
@Override public Answer execute(final MaintainCommand command, final LibvirtComputingResource libvirtComputingResource) { return new MaintainAnswer(command); } }
Mockito.when(reader.document(anyInt())).thenAnswer(new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); Object mock = invocation.getMock(); return document(fakeIndex((int)(Integer)args[0])); } });