Skip to content

Commit

Permalink
Fix 2701 too may files found (#2732)
Browse files Browse the repository at this point in the history
* Splitting up several variables for debugging.

* Checking if the 'database' value is not 'null' before invokig a method
-- this fixes incorrect match of multiple files caused by a (masked)
"null pointer exception".

* Restoring the previous (more compact) code style.

* Adding a unit test for the new fix.

* Removing unused member 'private String patternString'.

* Adding another test to MakeLabelWithoutDatabaseTest.java, to cover the
second 'if' branch in the 2701 fix.

* Removing parameter annotation comments from the tests in
MakeLabelWithoutDatabaseTest.java, since IntelliJ handles them
automagically.

* Removing unused commented-out class member.
  • Loading branch information
sauliusg authored and Siedlerchr committed Apr 13, 2017
1 parent 8c41684 commit e7fc94c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,13 @@ public static String makeLabel(BibEntry entry, String value, Character keywordDe
* form "pureauth..." which does not do this fallback
* substitution of editor.
*/
String authString = entry.getField(FieldName.AUTHOR)
.map(authorString -> normalize(database.resolveForStrings(authorString))).orElse("");
String authString;
if (database != null) {
authString = entry.getField(FieldName.AUTHOR)
.map(authorString -> normalize(database.resolveForStrings(authorString))).orElse("");
} else {
authString = entry.getField(FieldName.AUTHOR).orElse("");
}

if (val.startsWith("pure")) {
// remove the "pure" prefix so the remaining
Expand All @@ -534,8 +539,12 @@ public static String makeLabel(BibEntry entry, String value, Character keywordDe
}

if (authString.isEmpty()) {
authString = entry.getField(FieldName.EDITOR)
if (database != null) {
authString = entry.getField(FieldName.EDITOR)
.map(authorString -> normalize(database.resolveForStrings(authorString))).orElse("");
} else {
authString = entry.getField(FieldName.EDITOR).orElse("");
}
}

// Gather all author-related checks, so we don't
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jabref.logic.bibtexkeypattern;

import org.jabref.model.entry.BibEntry;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class MakeLabelWithoutDatabaseTest {

private BibEntry entry;

@Before
public void setUp() {
entry = new BibEntry();
entry.setField("author", "John Doe");
entry.setField("year", "2016");
entry.setField("title", "An awesome paper on JabRef");
}

@Test
public void makeLabelForFileSearch() {
String label =
BibtexKeyPatternUtil.makeLabel(entry, "auth", ',', null);
assertEquals("Doe", label);
}

@Test
public void makeEditorLabelForFileSearch() {
BibEntry localEntry = new BibEntry();
localEntry.setField("editor", "John Doe");
localEntry.setField("year", "2016");
localEntry.setField("title", "An awesome paper on JabRef");

String label =
BibtexKeyPatternUtil.makeLabel(localEntry, "auth", ',', null);
assertEquals("Doe", label);
}

}

0 comments on commit e7fc94c

Please sign in to comment.