VirtualMachineHandler { public List<ProcessDescription> listProcesses() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { List<ProcessDescription> ret = new ArrayList<ProcessDescription>(); Class vmClass = lookupVirtualMachineClass(); Method method = vmClass.getMethod("list"); List vmDescriptors = (List) method.invoke(null); for (Object descriptor : vmDescriptors) { Method idMethod = descriptor.getClass().getMethod("id"); String id = (String) idMethod.invoke(descriptor); Method displayMethod = descriptor.getClass().getMethod("displayName"); String display = (String) displayMethod.invoke(descriptor); ret.add(new ProcessDescription(id, display)); } return ret; } VirtualMachineHandler(OptionsAndArgs pOptions); Object attachVirtualMachine(); void detachAgent(Object pVm); List<ProcessDescription> listProcesses(); ProcessDescription findProcess(Pattern pPattern);  }
@Test public void listAndAttach() throws Exception, NoSuchMethodException, IllegalAccessException { List<ProcessDescription> procs = vmHandler.listProcesses(); assertTrue(procs.size() > 0); boolean foundAtLeastOne = false; for (ProcessDescription p : procs) { try { foundAtLeastOne |= tryAttach(p.getId()); } catch (Exception exp) { System.err.println("ERROR: " + p.getId() + " " + p.getDisplay() + ": " + exp); } } assertTrue(foundAtLeastOne); }