Skip to content

Commit

Permalink
Delete Sublass and move methods in base class
Browse files Browse the repository at this point in the history
Hopefully fixes problem for CI Server...
  • Loading branch information
Siedlerchr committed Jul 21, 2016
1 parent a2e8e28 commit e633c8f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
package net.sf.jabref;
package net.sf.jabref.logic.util.io;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import net.sf.jabref.BibtexTestData;
import net.sf.jabref.Globals;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.support.DevEnvironment;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;


/**
* A base class for Testing in JabRef that comes along with some useful
* functions.
*/
public class FileBasedTestCase {

protected BibDatabase database;
protected BibEntry entry;
protected Path rootDir;
private BibDatabase database;
private BibEntry entry;
private Path rootDir;

private String oldPdfDirectory;
private boolean oldUseRegExp;
Expand Down Expand Up @@ -72,6 +85,40 @@ public void setUp() throws IOException {

}

@Test
public void testFindAssociatedFiles() {

List<BibEntry> entries = Collections.singletonList(entry);
List<String> extensions = Arrays.asList("jpg", "pdf");
List<File> dirs = Arrays.asList(rootDir.resolve("graphicsDir").toFile(),
rootDir.resolve("pdfs").toFile());

Map<BibEntry, List<File>> results = FileUtil.findAssociatedFiles(entries, extensions, dirs, Globals.prefs);

assertEquals(2, results.get(entry).size());
assertTrue(results.get(entry)
.contains(rootDir.resolve(Paths.get("graphicsDir", "subDir", "HipKro03test.jpg")).toFile()));
assertFalse(results.get(entry)
.contains(rootDir.resolve(Paths.get("graphicsDir", "subDir", "HipKro03test.png")).toFile()));
assertTrue(results.get(entry).contains(rootDir.resolve(Paths.get("pdfs", "sub", "HipKro03-sub.pdf")).toFile()));
}

@Test
public void testFindFilesException() {
List<String> extensions = Arrays.asList("jpg", "pdf");
List<File> dirs = Arrays.asList(rootDir.resolve("asdfasdf/asdfasdf").toFile());
Set<File> results = FileFinder.findFiles(extensions, dirs);

assertEquals(0, results.size());
}

@Ignore("Fails on CI Server")
@Test(expected = NullPointerException.class)
public void testFindFilesNullPointerException() {

assumeFalse(DevEnvironment.isCIServer());
FileFinder.findFiles(null, null);
}
@After
public void tearDown() {

Expand Down
23 changes: 8 additions & 15 deletions src/test/java/net/sf/jabref/logic/util/io/FileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.mockito.Mockito.when;

public class FileUtilTest {

@Before
public void setUp() {
Globals.prefs = mock(JabRefPreferences.class);
Expand All @@ -34,7 +35,8 @@ public void tearDown() {
@Test
public void testGetLinkedFileNameDefault() {
// bibkey - title
when(Globals.prefs.get(JabRefPreferences.PREF_IMPORT_FILENAMEPATTERN)).thenReturn("\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}");
when(Globals.prefs.get(JabRefPreferences.PREF_IMPORT_FILENAMEPATTERN))
.thenReturn("\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}");

BibEntry entry = new BibEntry();
entry.setCiteKey("1234");
Expand Down Expand Up @@ -109,26 +111,17 @@ public void testGetFileExtensionNoExtension2String() {

@Test
public void uniquePathSubstrings() {
String[] pathArr = {
Paths.get("C:/uniquefile.bib").toString(),
Paths.get("C:/downloads/filename.bib").toString(),
Paths.get("C:/mypaper/bib/filename.bib").toString(),
Paths.get("C:/external/mypaper/bib/filename.bib").toString(),
""
};
String[] uniqArr = {
Paths.get("uniquefile.bib").toString(),
Paths.get("downloads/filename.bib").toString(),
String[] pathArr = {Paths.get("C:/uniquefile.bib").toString(),
Paths.get("C:/downloads/filename.bib").toString(), Paths.get("C:/mypaper/bib/filename.bib").toString(),
Paths.get("C:/external/mypaper/bib/filename.bib").toString(), ""};
String[] uniqArr = {Paths.get("uniquefile.bib").toString(), Paths.get("downloads/filename.bib").toString(),
Paths.get("C:/mypaper/bib/filename.bib").toString(),
Paths.get("external/mypaper/bib/filename.bib").toString(),
""
};
Paths.get("external/mypaper/bib/filename.bib").toString(), ""};
List<String> paths = Arrays.asList(pathArr);
List<String> uniqPath = Arrays.asList(uniqArr);

List<String> result = FileUtil.uniquePathSubstrings(paths);
assertEquals(uniqPath, result);
}


}
64 changes: 0 additions & 64 deletions src/test/java/net/sf/jabref/logic/util/io/UtilFindFileTest.java

This file was deleted.

0 comments on commit e633c8f

Please sign in to comment.