Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't report journal name as abbreviated when full name = abbreviated name #4116

Merged
merged 1 commit into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}