Skip to content

Real test linking real other entry #3214

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

Merged
merged 9 commits into from
Sep 14, 2017
40 changes: 36 additions & 4 deletions src/test/java/org/jabref/model/entry/EntryLinkListTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.model.entry;

import org.jabref.model.database.BibDatabase;
import org.junit.Before;
import org.junit.Test;

import java.util.List;
Expand All @@ -11,10 +12,29 @@

public class EntryLinkListTest {

private String key = "test";
private BibDatabase database = new BibDatabase();
private List<ParsedEntryLink> links = EntryLinkList.parse(key, database);
private ParsedEntryLink link = links.get(0);
private static final String key = "test";

private BibDatabase database;
private List<ParsedEntryLink> links;
private ParsedEntryLink link;
private BibEntry source;
private BibEntry target;

@Before
public void before() {
database = new BibDatabase();
links = EntryLinkList.parse(key, database);
link = links.get(0);
source = create("source");
target = create("target");
}

private BibEntry create(String citeKey) {
BibEntry entry = new BibEntry();
entry.setCiteKey(citeKey);
database.insertEntry(entry);
return entry;
}

@Test
public void givenFieldValueAndDatabaseWhenParsingThenExpectKey() {
Expand Down Expand Up @@ -42,4 +62,16 @@ public void givenNullFieldValueAndDatabaseWhenParsingThenExpectLinksIsEmpty() {
links = EntryLinkList.parse(null, database);
assertTrue(links.isEmpty());
}

@Test
public void givenTargetAndSourceWhenSourceCrossrefTargetThenSourceCrossrefsTarget() {
source.setField(FieldName.CROSSREF, "target");
assertSourceCrossrefsTarget(target, source);
}

private void assertSourceCrossrefsTarget(BibEntry target, BibEntry source) {
Optional<String> sourceCrossref = source.getField(FieldName.CROSSREF);
Optional<String> targetCiteKey = target.getCiteKeyOptional();
assertEquals(sourceCrossref, targetCiteKey);
}
}