{"action":"created","comment":{"url":"https://api.github.com/repos/JabRef/jabref/pulls/comments/71970465","id":71970465,"diff_hunk":"@@ -0,0 +1,124 @@\n+package net.sf.jabref.logic.util.io;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.nio.file.Files;\n+import java.nio.file.Path;\n+import java.nio.file.Paths;\n+import java.util.Arrays;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+import java.util.stream.Stream;\n+\n+import net.sf.jabref.BibtexTestData;\n+import net.sf.jabref.Globals;\n+import net.sf.jabref.model.database.BibDatabase;\n+import net.sf.jabref.model.entry.BibEntry;\n+import net.sf.jabref.preferences.JabRefPreferences;\n+import net.sf.jabref.support.DevEnvironment;\n+\n+import org.junit.After;\n+import org.junit.Before;\n+import org.junit.Ignore;\n+import org.junit.Test;\n+import static org.junit.Assert.assertEquals;\n+import static org.junit.Assert.assertFalse;\n+import static org.junit.Assert.assertTrue;\n+import static org.junit.Assume.assumeFalse;\n+import static org.mockito.Mockito.mock;\n+import static org.mockito.Mockito.when;\n+\n+public class FileBasedTestCase {\n+\n+    private BibEntry entry;\n+    private Path rootDir;\n+\n+\n+    @Before\n+    public void setUp() throws IOException {\n+        Globals.prefs = mock(JabRefPreferences.class);\n+\n+        BibDatabase database = BibtexTestData.getBibtexDatabase();\n+        entry = database.getEntries().iterator().next();\n+\n+        rootDir = Files.createTempDirectory(\"UtilFindFileTest\");\n+\n+\n+\n+        Path subDir = Files.createDirectory(rootDir.resolve(\"Organization Science\"));\n+        Path pdfSubDir = Files.createDirectory(rootDir.resolve(\"pdfs\"));\n+\n+        assertTrue(Files.exists(Files.createFile(subDir.resolve(\"HipKro03 - Hello.pdf\"))));\n+        assertTrue(Files.exists(Files.createFile(rootDir.resolve(\"HipKro03 - Hello.pdf\"))));\n+\n+        Path pdfSubSubDir = Files.createDirectory(pdfSubDir.resolve(\"sub\"));\n+        assertTrue(Files.exists(Files.createFile(pdfSubSubDir.resolve(\"HipKro03-sub.pdf\"))));\n+\n+        Files.createDirectory(rootDir.resolve(\"2002\"));\n+        Path dir2003 = Files.createDirectory(rootDir.resolve(\"2003\"));\n+        assertTrue(Files.exists(Files.createFile(dir2003.resolve(\"Paper by HipKro03.pdf\"))));\n+\n+        Path dirTest = Files.createDirectory(rootDir.resolve(\"test\"));\n+        assertTrue(Files.exists(Files.createFile(dirTest.resolve(\".TEST\"))));\n+        assertTrue(Files.exists(Files.createFile(dirTest.resolve(\"TEST[\"))));\n+        assertTrue(Files.exists(Files.createFile(dirTest.resolve(\"TE.ST\"))));\n+        assertTrue(Files.exists(Files.createFile(dirTest.resolve(\"foo.dat\"))));\n+\n+        Path graphicsDir = Files.createDirectory(rootDir.resolve(\"graphicsDir\"));\n+        Path graphicsSubDir = Files.createDirectories(graphicsDir.resolve(\"subDir\"));\n+\n+        assertTrue(Files.exists(Files.createFile(graphicsSubDir.resolve(\"HipKro03test.jpg\"))));\n+        assertTrue(Files.exists(Files.createFile(graphicsSubDir.resolve(\"HipKro03test.png\"))));\n+\n+    }\n+\n+    @Test\n+    public void testFindAssociatedFiles() {\n+\n+        List<BibEntry> entries = Collections.singletonList(entry);\n+        List<String> extensions = Arrays.asList(\"jpg\", \"pdf\");\n+        List<File> dirs = Arrays.asList(rootDir.resolve(\"graphicsDir\").toFile(), rootDir.resolve(\"pdfs\").toFile());\n+\n+        when(Globals.prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY)).thenReturn(false);\n+\n+        Map<BibEntry, List<File>> results = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs);\n+\n+        assertEquals(2, results.get(entry).size());\n+        assertTrue(results.get(entry)\n+                .contains(rootDir.resolve(Paths.get(\"graphicsDir\", \"subDir\", \"HipKro03test.jpg\")).toFile()));\n+        assertFalse(results.get(entry)\n+                .contains(rootDir.resolve(Paths.get(\"graphicsDir\", \"subDir\", \"HipKro03test.png\")).toFile()));\n+        assertTrue(results.get(entry).contains(rootDir.resolve(Paths.get(\"pdfs\", \"sub\", \"HipKro03-sub.pdf\")).toFile()));\n+    }\n+\n+    @Test\n+    public void testFindFilesException() {\n+        List<String> extensions = Arrays.asList(\"jpg\", \"pdf\");\n+        List<File> dirs = Arrays.asList(rootDir.resolve(\"asdfasdf/asdfasdf\").toFile());\n+        Set<File> results = FileFinder.findFiles(extensions, dirs);\n+\n+        assertEquals(0, results.size());\n+    }\n+\n+    @Ignore(\"Fails on CI Server\")\n+    @Test(expected = NullPointerException.class)\n+    public void testFindFilesNullPointerException() {\n+\n+        assumeFalse(DevEnvironment.isCIServer());\n+        FileFinder.findFiles(null, null);\n+    }\n+\n+    @After\n+    public void tearDown() throws IOException {\n+\n+        Globals.prefs = null;","path":"src/test/java/net/sf/jabref/logic/util/io/FileBasedTestCase.java","position":116,"original_position":116,"commit_id":"80e812f23157a23e2accf652b3f60df1b427f8e5","original_commit_id":"80e812f23157a23e2accf652b3f60df1b427f8e5","user":{"login":"tobiasdiez","id":5037600,"avatar_url":"https://avatars.githubusercontent.com/u/5037600?v=3","gravatar_id":"","url":"https://api.github.com/users/tobiasdiez","html_url":"https://github.com/tobiasdiez","followers_url":"https://api.github.com/users/tobiasdiez/followers","following_url":"https://api.github.com/users/tobiasdiez/following{/other_user}","gists_url":"https://api.github.com/users/tobiasdiez/gists{/gist_id}","starred_url":"https://api.github.com/users/tobiasdiez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobiasdiez/subscriptions","organizations_url":"https://api.github.com/users/tobiasdiez/orgs","repos_url":"https://api.github.com/users/tobiasdiez/repos","events_url":"https://api.github.com/users/tobiasdiez/events{/privacy}","received_events_url":"https://api.github.com/users/tobiasdiez/received_events","type":"User","site_admin":false},"body":"the `Globals.prefs = null` is  not required.","created_at":"2016-07-23T10:05:48Z","updated_at":"2016-07-23T10:05:48Z","html_url":"https://github.com/JabRef/jabref/pull/1596#discussion_r71970465","pull_request_url":"https://api.github.com/repos/JabRef/jabref/pulls/1596","_links":{"self":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/comments/71970465"},"html":{"href":"https://github.com/JabRef/jabref/pull/1596#discussion_r71970465"},"pull_request":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/1596"}}},"pull_request":{"url":"https://api.github.com/repos/JabRef/jabref/pulls/1596","id":77714744,"html_url":"https://github.com/JabRef/jabref/pull/1596","diff_url":"https://github.com/JabRef/jabref/pull/1596.diff","patch_url":"https://github.com/JabRef/jabref/pull/1596.patch","issue_url":"https://api.github.com/repos/JabRef/jabref/issues/1596","number":1596,"state":"open","locked":false,"title":"Cleanup FindFile and asssociated tests","user":{"login":"Siedlerchr","id":320228,"avatar_url":"https://avatars.githubusercontent.com/u/320228?v=3","gravatar_id":"","url":"https://api.github.com/users/Siedlerchr","html_url":"https://github.com/Siedlerchr","followers_url":"https://api.github.com/users/Siedlerchr/followers","following_url":"https://api.github.com/users/Siedlerchr/following{/other_user}","gists_url":"https://api.github.com/users/Siedlerchr/gists{/gist_id}","starred_url":"https://api.github.com/users/Siedlerchr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siedlerchr/subscriptions","organizations_url":"https://api.github.com/users/Siedlerchr/orgs","repos_url":"https://api.github.com/users/Siedlerchr/repos","events_url":"https://api.github.com/users/Siedlerchr/events{/privacy}","received_events_url":"https://api.github.com/users/Siedlerchr/received_events","type":"User","site_admin":false},"body":"Cleaned up the findFiles method\r\nReworked tests, added some new Tests\r\nTests should now work in Linux, too \r\n\r\n- [X] Tests created for changes\r\n\r\n\r\n","created_at":"2016-07-16T17:20:39Z","updated_at":"2016-07-23T10:05:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b33a58fccd96bd9b3252b102fa54cc413db480b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JabRef/jabref/pulls/1596/commits","review_comments_url":"https://api.github.com/repos/JabRef/jabref/pulls/1596/comments","review_comment_url":"https://api.github.com/repos/JabRef/jabref/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JabRef/jabref/issues/1596/comments","statuses_url":"https://api.github.com/repos/JabRef/jabref/statuses/80e812f23157a23e2accf652b3f60df1b427f8e5","head":{"label":"Siedlerchr:directoryRenamePattern","ref":"directoryRenamePattern","sha":"80e812f23157a23e2accf652b3f60df1b427f8e5","user":{"login":"Siedlerchr","id":320228,"avatar_url":"https://avatars.githubusercontent.com/u/320228?v=3","gravatar_id":"","url":"https://api.github.com/users/Siedlerchr","html_url":"https://github.com/Siedlerchr","followers_url":"https://api.github.com/users/Siedlerchr/followers","following_url":"https://api.github.com/users/Siedlerchr/following{/other_user}","gists_url":"https://api.github.com/users/Siedlerchr/gists{/gist_id}","starred_url":"https://api.github.com/users/Siedlerchr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siedlerchr/subscriptions","organizations_url":"https://api.github.com/users/Siedlerchr/orgs","repos_url":"https://api.github.com/users/Siedlerchr/repos","events_url":"https://api.github.com/users/Siedlerchr/events{/privacy}","received_events_url":"https://api.github.com/users/Siedlerchr/received_events","type":"User","site_admin":false},"repo":{"id":50295649,"name":"jabref","full_name":"Siedlerchr/jabref","owner":{"login":"Siedlerchr","id":320228,"avatar_url":"https://avatars.githubusercontent.com/u/320228?v=3","gravatar_id":"","url":"https://api.github.com/users/Siedlerchr","html_url":"https://github.com/Siedlerchr","followers_url":"https://api.github.com/users/Siedlerchr/followers","following_url":"https://api.github.com/users/Siedlerchr/following{/other_user}","gists_url":"https://api.github.com/users/Siedlerchr/gists{/gist_id}","starred_url":"https://api.github.com/users/Siedlerchr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siedlerchr/subscriptions","organizations_url":"https://api.github.com/users/Siedlerchr/orgs","repos_url":"https://api.github.com/users/Siedlerchr/repos","events_url":"https://api.github.com/users/Siedlerchr/events{/privacy}","received_events_url":"https://api.github.com/users/Siedlerchr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Siedlerchr/jabref","description":"Graphical Java application for managing bibtex (.bib) databases","fork":true,"url":"https://api.github.com/repos/Siedlerchr/jabref","forks_url":"https://api.github.com/repos/Siedlerchr/jabref/forks","keys_url":"https://api.github.com/repos/Siedlerchr/jabref/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Siedlerchr/jabref/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Siedlerchr/jabref/teams","hooks_url":"https://api.github.com/repos/Siedlerchr/jabref/hooks","issue_events_url":"https://api.github.com/repos/Siedlerchr/jabref/issues/events{/number}","events_url":"https://api.github.com/repos/Siedlerchr/jabref/events","assignees_url":"https://api.github.com/repos/Siedlerchr/jabref/assignees{/user}","branches_url":"https://api.github.com/repos/Siedlerchr/jabref/branches{/branch}","tags_url":"https://api.github.com/repos/Siedlerchr/jabref/tags","blobs_url":"https://api.github.com/repos/Siedlerchr/jabref/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Siedlerchr/jabref/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Siedlerchr/jabref/git/refs{/sha}","trees_url":"https://api.github.com/repos/Siedlerchr/jabref/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Siedlerchr/jabref/statuses/{sha}","languages_url":"https://api.github.com/repos/Siedlerchr/jabref/languages","stargazers_url":"https://api.github.com/repos/Siedlerchr/jabref/stargazers","contributors_url":"https://api.github.com/repos/Siedlerchr/jabref/contributors","subscribers_url":"https://api.github.com/repos/Siedlerchr/jabref/subscribers","subscription_url":"https://api.github.com/repos/Siedlerchr/jabref/subscription","commits_url":"https://api.github.com/repos/Siedlerchr/jabref/commits{/sha}","git_commits_url":"https://api.github.com/repos/Siedlerchr/jabref/git/commits{/sha}","comments_url":"https://api.github.com/repos/Siedlerchr/jabref/comments{/number}","issue_comment_url":"https://api.github.com/repos/Siedlerchr/jabref/issues/comments{/number}","contents_url":"https://api.github.com/repos/Siedlerchr/jabref/contents/{+path}","compare_url":"https://api.github.com/repos/Siedlerchr/jabref/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Siedlerchr/jabref/merges","archive_url":"https://api.github.com/repos/Siedlerchr/jabref/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Siedlerchr/jabref/downloads","issues_url":"https://api.github.com/repos/Siedlerchr/jabref/issues{/number}","pulls_url":"https://api.github.com/repos/Siedlerchr/jabref/pulls{/number}","milestones_url":"https://api.github.com/repos/Siedlerchr/jabref/milestones{/number}","notifications_url":"https://api.github.com/repos/Siedlerchr/jabref/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Siedlerchr/jabref/labels{/name}","releases_url":"https://api.github.com/repos/Siedlerchr/jabref/releases{/id}","deployments_url":"https://api.github.com/repos/Siedlerchr/jabref/deployments","created_at":"2016-01-24T16:11:57Z","updated_at":"2016-01-24T16:12:01Z","pushed_at":"2016-07-22T19:29:55Z","git_url":"git://github.com/Siedlerchr/jabref.git","ssh_url":"git@github.com:Siedlerchr/jabref.git","clone_url":"https://github.com/Siedlerchr/jabref.git","svn_url":"https://github.com/Siedlerchr/jabref","homepage":"http://www.jabref.org/","size":83889,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"JabRef:master","ref":"master","sha":"23fdfe2a05e4b617ba9b9ed66708c0e1b818a0c3","user":{"login":"JabRef","id":3914421,"avatar_url":"https://avatars.githubusercontent.com/u/3914421?v=3","gravatar_id":"","url":"https://api.github.com/users/JabRef","html_url":"https://github.com/JabRef","followers_url":"https://api.github.com/users/JabRef/followers","following_url":"https://api.github.com/users/JabRef/following{/other_user}","gists_url":"https://api.github.com/users/JabRef/gists{/gist_id}","starred_url":"https://api.github.com/users/JabRef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JabRef/subscriptions","organizations_url":"https://api.github.com/users/JabRef/orgs","repos_url":"https://api.github.com/users/JabRef/repos","events_url":"https://api.github.com/users/JabRef/events{/privacy}","received_events_url":"https://api.github.com/users/JabRef/received_events","type":"Organization","site_admin":false},"repo":{"id":17634071,"name":"jabref","full_name":"JabRef/jabref","owner":{"login":"JabRef","id":3914421,"avatar_url":"https://avatars.githubusercontent.com/u/3914421?v=3","gravatar_id":"","url":"https://api.github.com/users/JabRef","html_url":"https://github.com/JabRef","followers_url":"https://api.github.com/users/JabRef/followers","following_url":"https://api.github.com/users/JabRef/following{/other_user}","gists_url":"https://api.github.com/users/JabRef/gists{/gist_id}","starred_url":"https://api.github.com/users/JabRef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JabRef/subscriptions","organizations_url":"https://api.github.com/users/JabRef/orgs","repos_url":"https://api.github.com/users/JabRef/repos","events_url":"https://api.github.com/users/JabRef/events{/privacy}","received_events_url":"https://api.github.com/users/JabRef/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/JabRef/jabref","description":"Graphical Java application for managing BibTeX and Biblatex (.bib) databases","fork":false,"url":"https://api.github.com/repos/JabRef/jabref","forks_url":"https://api.github.com/repos/JabRef/jabref/forks","keys_url":"https://api.github.com/repos/JabRef/jabref/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JabRef/jabref/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JabRef/jabref/teams","hooks_url":"https://api.github.com/repos/JabRef/jabref/hooks","issue_events_url":"https://api.github.com/repos/JabRef/jabref/issues/events{/number}","events_url":"https://api.github.com/repos/JabRef/jabref/events","assignees_url":"https://api.github.com/repos/JabRef/jabref/assignees{/user}","branches_url":"https://api.github.com/repos/JabRef/jabref/branches{/branch}","tags_url":"https://api.github.com/repos/JabRef/jabref/tags","blobs_url":"https://api.github.com/repos/JabRef/jabref/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JabRef/jabref/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JabRef/jabref/git/refs{/sha}","trees_url":"https://api.github.com/repos/JabRef/jabref/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JabRef/jabref/statuses/{sha}","languages_url":"https://api.github.com/repos/JabRef/jabref/languages","stargazers_url":"https://api.github.com/repos/JabRef/jabref/stargazers","contributors_url":"https://api.github.com/repos/JabRef/jabref/contributors","subscribers_url":"https://api.github.com/repos/JabRef/jabref/subscribers","subscription_url":"https://api.github.com/repos/JabRef/jabref/subscription","commits_url":"https://api.github.com/repos/JabRef/jabref/commits{/sha}","git_commits_url":"https://api.github.com/repos/JabRef/jabref/git/commits{/sha}","comments_url":"https://api.github.com/repos/JabRef/jabref/comments{/number}","issue_comment_url":"https://api.github.com/repos/JabRef/jabref/issues/comments{/number}","contents_url":"https://api.github.com/repos/JabRef/jabref/contents/{+path}","compare_url":"https://api.github.com/repos/JabRef/jabref/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JabRef/jabref/merges","archive_url":"https://api.github.com/repos/JabRef/jabref/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JabRef/jabref/downloads","issues_url":"https://api.github.com/repos/JabRef/jabref/issues{/number}","pulls_url":"https://api.github.com/repos/JabRef/jabref/pulls{/number}","milestones_url":"https://api.github.com/repos/JabRef/jabref/milestones{/number}","notifications_url":"https://api.github.com/repos/JabRef/jabref/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JabRef/jabref/labels{/name}","releases_url":"https://api.github.com/repos/JabRef/jabref/releases{/id}","deployments_url":"https://api.github.com/repos/JabRef/jabref/deployments","created_at":"2014-03-11T14:48:42Z","updated_at":"2016-07-20T10:15:18Z","pushed_at":"2016-07-23T10:05:31Z","git_url":"git://github.com/JabRef/jabref.git","ssh_url":"git@github.com:JabRef/jabref.git","clone_url":"https://github.com/JabRef/jabref.git","svn_url":"https://github.com/JabRef/jabref","homepage":"http://www.jabref.org","size":90136,"stargazers_count":308,"watchers_count":308,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":245,"mirror_url":null,"open_issues_count":192,"forks":245,"open_issues":192,"watchers":308,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/1596"},"html":{"href":"https://github.com/JabRef/jabref/pull/1596"},"issue":{"href":"https://api.github.com/repos/JabRef/jabref/issues/1596"},"comments":{"href":"https://api.github.com/repos/JabRef/jabref/issues/1596/comments"},"review_comments":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/1596/comments"},"review_comment":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JabRef/jabref/pulls/1596/commits"},"statuses":{"href":"https://api.github.com/repos/JabRef/jabref/statuses/80e812f23157a23e2accf652b3f60df1b427f8e5"}}}}
{"actor":{"display_login":"tobiasdiez"}}