@Test public void getReturnsEmptyIfUserNameCannotBeFound() { advapi.setOpenProcessTokenReturnValue(true); advapi.setOpenProcessTokenTokenHandle(123); TokenUserFinder userFinder = new TokenUserFinder(advapi) { @Override public Optional<Advapi32.TokenUser> findTokenUser(ProcessToken token) { Memory memory = new Memory(8); memory.write(0, new int[] {123, 321}, 0, 2); return Optional.of(new Advapi32.TokenUser(memory)); } }; TokenOwnerNameFinder nameNonFinder = new TokenOwnerNameFinder(advapi) { @Override public Optional<String> getUserName(Advapi32.TokenUser user) { return Optional.empty(); } }; getter = new WindowsProcessOwnerGetter(opener, userFinder, nameNonFinder); Optional<String> ret = getter.get(procHandle); assertFalse(ret.isPresent()); }
@Override public Optional<String> get(ProcessHandle processHandle) { Objects.requireNonNull(processHandle, "processHandle cannot be null!"); try (ProcessToken token = tokenOpener.openToken(processHandle)) { return tokenUserFinder.findTokenUser(token).flatMap(tokenOwnerFinder::getUserName); } catch (TokenOpenException ex) { return Optional.empty(); } }
WindowsProcessOwnerGetter implements ProcessOwnerGetter { @Override public Optional<String> get(ProcessHandle processHandle) { Objects.requireNonNull(processHandle, "processHandle cannot be null!"); try (ProcessToken token = tokenOpener.openToken(processHandle)) { return tokenUserFinder.findTokenUser(token).flatMap(tokenOwnerFinder::getUserName); } catch (TokenOpenException ex) { return Optional.empty(); } } }
WindowsProcessOwnerGetter implements ProcessOwnerGetter { @Override public Optional<String> get(ProcessHandle processHandle) { Objects.requireNonNull(processHandle, "processHandle cannot be null!"); try (ProcessToken token = tokenOpener.openToken(processHandle)) { return tokenUserFinder.findTokenUser(token).flatMap(tokenOwnerFinder::getUserName); } catch (TokenOpenException ex) { return Optional.empty(); } } WindowsProcessOwnerGetter(ProcessTokenOpener tokenOpener,
                                     TokenUserFinder userFinder,
                                     TokenOwnerNameFinder nameFinder); }
WindowsProcessOwnerGetter implements ProcessOwnerGetter { @Override public Optional<String> get(ProcessHandle processHandle) { Objects.requireNonNull(processHandle, "processHandle cannot be null!"); try (ProcessToken token = tokenOpener.openToken(processHandle)) { return tokenUserFinder.findTokenUser(token).flatMap(tokenOwnerFinder::getUserName); } catch (TokenOpenException ex) { return Optional.empty(); } } WindowsProcessOwnerGetter(ProcessTokenOpener tokenOpener,
                                     TokenUserFinder userFinder,
                                     TokenOwnerNameFinder nameFinder); @Override Optional<String> get(ProcessHandle processHandle); }
WindowsProcessOwnerGetter implements ProcessOwnerGetter { @Override public Optional<String> get(ProcessHandle processHandle) { Objects.requireNonNull(processHandle, "processHandle cannot be null!"); try (ProcessToken token = tokenOpener.openToken(processHandle)) { return tokenUserFinder.findTokenUser(token).flatMap(tokenOwnerFinder::getUserName); } catch (TokenOpenException ex) { return Optional.empty(); } } WindowsProcessOwnerGetter(ProcessTokenOpener tokenOpener,
                                     TokenUserFinder userFinder,
                                     TokenOwnerNameFinder nameFinder); @Override Optional<String> get(ProcessHandle processHandle);  }