### Question:
UserProfile extends BaseVersionedNetworkContent { public Index getFileByPath(File file, File root) { File currentFile = new File(file.getAbsolutePath()); List<String> filePath = new ArrayList<String>(); while (!root.equals(currentFile) && currentFile != null) { filePath.add(currentFile.getName()); currentFile = currentFile.getParentFile(); } Collections.reverse(filePath); FolderIndex currentIndex = this.root; for (String fileName : filePath) { Index child = currentIndex.getChildByName(fileName); if (child == null) { return null; } else if (child instanceof FolderIndex) { currentIndex = (FolderIndex) child; } else if (child.getName().equals(file.getName())) { return child; } } return currentIndex; } UserProfile(String userId, KeyPair encryptionKeys, KeyPair protectionKeys); String getUserId(); KeyPair getEncryptionKeys(); KeyPair getProtectionKeys(); FolderIndex getRoot(); @Override int getTimeToLive(); Index getFileById(PublicKey fileId); Index getFileByPath(File file, File root);  }### Answer:
@Test public void getFileByPath() throws IOException { FolderIndex root = userProfile.getRoot(); FolderIndex folderIndex1 = new FolderIndex(root, generateRSAKeyPair(RSA_KEYLENGTH.BIT_512), randomString()); FileIndex fileIndex1 = new FileIndex(folderIndex1, generateRSAKeyPair(RSA_KEYLENGTH.BIT_512), randomString(), "bla".getBytes()); FileIndex fileIndex2 = new FileIndex(folderIndex1, generateRSAKeyPair(RSA_KEYLENGTH.BIT_512), randomString(), "blubb".getBytes()); FolderIndex folderIndex2 = new FolderIndex(folderIndex1, generateRSAKeyPair(RSA_KEYLENGTH.BIT_512), randomString()); FileIndex fileIndex3 = new FileIndex(folderIndex2, generateRSAKeyPair(RSA_KEYLENGTH.BIT_512), randomString(), "bla".getBytes()); File rootFile = tempFolder.newFolder(); File folder1 = new File(rootFile, folderIndex1.getName()); File file1 = new File(folder1, fileIndex1.getName()); File file2 = new File(folder1, fileIndex2.getName()); File folder2 = new File(folder1, folderIndex2.getName()); File file3 = new File(folder2, fileIndex3.getName()); Assert.assertEquals(root, userProfile.getFileByPath(rootFile, rootFile)); Assert.assertEquals(folderIndex1, userProfile.getFileByPath(folder1, rootFile)); Assert.assertEquals(fileIndex1, userProfile.getFileByPath(file1, rootFile)); Assert.assertEquals(fileIndex2, userProfile.getFileByPath(file2, rootFile)); Assert.assertEquals(folderIndex2, userProfile.getFileByPath(folder2, rootFile)); Assert.assertEquals(fileIndex3, userProfile.getFileByPath(file3, rootFile)); }