@Test public void collectGetsUnknownOwnerIfOwnerGetterReturnsEmpty() { processOpener.doNotThrowExceptionOnOpen(); ownerGetter = handle -> Optional.empty(); NativeProcess proc = collector.collect(444); assertEquals(NativeProcess.UNKNOWN_OWNER, proc.getOwner()); }
@Override public NativeProcess collect(int pid) { NativeProcess process = new NativeProcessImpl( pid, NativeProcess.UNKNOWN_DESCRIPTION, NativeProcess.UNKNOWN_OWNER); try (ProcessHandle handle = processOpener.open(pid, ProcessAccessFlags.QUERY_INFORMATION)) { String description = descriptionGetter.get(handle).orElse(NativeProcess.UNKNOWN_DESCRIPTION); String owner = ownerGetter.get(handle).orElse(NativeProcess.UNKNOWN_OWNER); process.setDescription(description); process.setOwner(owner); } catch (ProcessOpenException ex) { } return process; }
WindowsNativeProcessCollector implements NativeProcessCollector { @Override public NativeProcess collect(int pid) { NativeProcess process = new NativeProcessImpl( pid, NativeProcess.UNKNOWN_DESCRIPTION, NativeProcess.UNKNOWN_OWNER); try (ProcessHandle handle = processOpener.open(pid, ProcessAccessFlags.QUERY_INFORMATION)) { String description = descriptionGetter.get(handle).orElse(NativeProcess.UNKNOWN_DESCRIPTION); String owner = ownerGetter.get(handle).orElse(NativeProcess.UNKNOWN_OWNER); process.setDescription(description); process.setOwner(owner); } catch (ProcessOpenException ex) { } return process; } }
WindowsNativeProcessCollector implements NativeProcessCollector { @Override public NativeProcess collect(int pid) { NativeProcess process = new NativeProcessImpl( pid, NativeProcess.UNKNOWN_DESCRIPTION, NativeProcess.UNKNOWN_OWNER); try (ProcessHandle handle = processOpener.open(pid, ProcessAccessFlags.QUERY_INFORMATION)) { String description = descriptionGetter.get(handle).orElse(NativeProcess.UNKNOWN_DESCRIPTION); String owner = ownerGetter.get(handle).orElse(NativeProcess.UNKNOWN_OWNER); process.setDescription(description); process.setOwner(owner); } catch (ProcessOpenException ex) { } return process; } WindowsNativeProcessCollector(ProcessOpener processOpener,
                                         ProcessOwnerGetter ownerGetter,
                                         ProcessDescriptionGetter descriptionGetter); }
WindowsNativeProcessCollector implements NativeProcessCollector { @Override public NativeProcess collect(int pid) { NativeProcess process = new NativeProcessImpl( pid, NativeProcess.UNKNOWN_DESCRIPTION, NativeProcess.UNKNOWN_OWNER); try (ProcessHandle handle = processOpener.open(pid, ProcessAccessFlags.QUERY_INFORMATION)) { String description = descriptionGetter.get(handle).orElse(NativeProcess.UNKNOWN_DESCRIPTION); String owner = ownerGetter.get(handle).orElse(NativeProcess.UNKNOWN_OWNER); process.setDescription(description); process.setOwner(owner); } catch (ProcessOpenException ex) { } return process; } WindowsNativeProcessCollector(ProcessOpener processOpener,
                                         ProcessOwnerGetter ownerGetter,
                                         ProcessDescriptionGetter descriptionGetter); @Override NativeProcess collect(int pid); }
WindowsNativeProcessCollector implements NativeProcessCollector { @Override public NativeProcess collect(int pid) { NativeProcess process = new NativeProcessImpl( pid, NativeProcess.UNKNOWN_DESCRIPTION, NativeProcess.UNKNOWN_OWNER); try (ProcessHandle handle = processOpener.open(pid, ProcessAccessFlags.QUERY_INFORMATION)) { String description = descriptionGetter.get(handle).orElse(NativeProcess.UNKNOWN_DESCRIPTION); String owner = ownerGetter.get(handle).orElse(NativeProcess.UNKNOWN_OWNER); process.setDescription(description); process.setOwner(owner); } catch (ProcessOpenException ex) { } return process; } WindowsNativeProcessCollector(ProcessOpener processOpener,
                                         ProcessOwnerGetter ownerGetter,
                                         ProcessDescriptionGetter descriptionGetter); @Override NativeProcess collect(int pid);  }