Skip to content

Commit

Permalink
Fix #4115: Don't report journal name as abbreviated when full name = …
Browse files Browse the repository at this point in the history
…abbreviated name
  • Loading branch information
tobiasdiez committed Jun 7, 2018
1 parent b4b632b commit 4f19e7c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where in rare cases entries where overlayed in the main table. https://github.com/JabRef/jabref/issues/3281
- We fixed an issue where selecting a group messed up the focus of the main table / entry editor. https://github.com/JabRef/jabref/issues/3367
- We fixed an issue where composite author names were sorted incorrectly. https://github.com/JabRef/jabref/issues/2828
- We fixed an issue where some journal names were wrongly marked as abbreviated. [#4115](https://github.com/JabRef/jabref/issues/4115)
- We fixed an issue where the custom file column were sorted incorrectly. https://github.com/JabRef/jabref/issues/3119
- We fixed an issues where the entry losses focus when a field is edited and at the same time used for sorting. https://github.com/JabRef/jabref/issues/3373
- We fixed an issue where the menu on Mac OS was not displayed in the usual Mac-specific way. https://github.com/JabRef/jabref/issues/3146
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,28 @@ private static boolean isMatched(String name, Abbreviation abbreviation) {
}

private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviation) {
return name.equalsIgnoreCase(abbreviation.getIsoAbbreviation())
boolean isAbbreviated = name.equalsIgnoreCase(abbreviation.getIsoAbbreviation())
|| name.equalsIgnoreCase(abbreviation.getMedlineAbbreviation());
boolean isExpanded = name.equalsIgnoreCase(abbreviation.getName());
return isAbbreviated && !isExpanded;
}

public int size() {
return abbreviations.size();
}

/**
* Returns true if the given journal name is contained in the list either in its full form (e.g Physical Review
* Letters) or its abbreviated form (e.g. Phys. Rev. Lett.).
*/
public boolean isKnownName(String journalName) {
return abbreviations.stream().anyMatch(abbreviation -> isMatched(journalName.trim(), abbreviation));
}

/**
* Returns true if the given journal name is in its abbreviated form (e.g. Phys. Rev. Lett.). The test is strict,
* i.e. journals whose abbreviation is the same as the full name are not considered
*/
public boolean isAbbreviatedName(String journalName) {
return abbreviations.stream().anyMatch(abbreviation -> isMatchedAbbreviated(journalName.trim(), abbreviation));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.jabref.logic.journals.Abbreviation;
import org.jabref.logic.journals.JournalAbbreviationRepository;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

class AbbreviationCheckerTest {

private JournalAbbreviationRepository abbreviationRepository;
private AbbreviationChecker checker;

@BeforeEach
void setUp() {
abbreviationRepository = new JournalAbbreviationRepository(new Abbreviation("Test Journal", "T. J."));
checker = new AbbreviationChecker(abbreviationRepository);
}

@Test
void checkValueComplainsAboutAbbreviatedJournalName() {
assertNotEquals(Optional.empty(), checker.checkValue("T. J."));
}

@Test
void checkValueDoesNotComplainAboutJournalNameThatHasSameAbbreviation() {
abbreviationRepository.addEntry(new Abbreviation("Journal", "Journal"));
assertEquals(Optional.empty(), checker.checkValue("Journal"));
}
}

0 comments on commit 4f19e7c

Please sign in to comment.