title: How to Mock FileSystem function
body: <p>I do not know how to mock the section where I'm changing the file's owner from line <code>Path path = newFile.toPath();</code> to the end.</p>
  
  <p>Here's my function :</p>
  
  <pre><code>@RequestMapping(value = "/upload", method = RequestMethod.POST)
      @ResponseBody
      public String uploadEndpoint(@RequestParam("file") MultipartFile file,
                                   @RequestParam("usernameSession") String usernameSession,
                                   @RequestHeader("current-folder") String folder) throws IOException {
  
  
          String[] pathArray = file.getOriginalFilename().split("[\\\\\\/]");
          String originalName = pathArray[pathArray.length-1];
          LOGGER.info("Upload triggerred with : {} , filename : {}", originalName, file.getName());
          String workingDir = URLDecoder.decode(folder.replace("!", "."),
                  StandardCharsets.UTF_8.name())
                  .replace("|", File.separator);
          LOGGER.info("The file will be moved to : {}", workingDir);
          File newFile = new File(workingDir + File.separator + originalName);
          //UserPrincipal owner = Files.getOwner(newFile.toPath());
  
          file.transferTo(newFile);
  
          Path path = newFile.toPath();
          FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
          UserPrincipal owner = foav.getOwner();
          System.out.format("Original owner  of  %s  is %s%n", path, owner.getName());
  
          FileSystem fs = FileSystems.getDefault();
          UserPrincipalLookupService upls = fs.getUserPrincipalLookupService();
  
          UserPrincipal newOwner = upls.lookupPrincipalByName(usernameSession);
          foav.setOwner(newOwner);
  
          UserPrincipal changedOwner = foav.getOwner();
          System.out.format("New owner  of  %s  is %s%n", path,
                  changedOwner.getName());
  
          return "ok";
      }
  </code></pre>
  
  <p>And here's the test :</p>
  
  <pre><code>@Test
      public void uploadEndpointTest() throws Exception {
          PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file);
          Mockito.when(multipartFile.getOriginalFilename()).thenReturn("src/test/resources/download/test.txt");
          assertEquals("ok", fileExplorerController.uploadEndpoint(multipartFile, "userName", "src/test/resources/download"));
      }
  </code></pre>
  
  <p>I got an exception because "userName" is not a user. I'd like to mock the call where it looks for a match in windows's users. It works when I set my window's username instead of "userName", but I can't let my window's username.</p>
  
  <p>I tried to mock <code>fs.getUserPrincipalLookupService()</code>; and <code>upls.lookupPrincipalByName(usernameSession);</code> but I do not know what to return to mock the call.</p>
  
  <p>Many thanks !</p>