Search in sources :

Example 21 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method getUsedStrings.

@Test
public void getUsedStrings() {
    BibEntry entry = new BibEntry(IdGenerator.next());
    entry.setField("author", "#AAA#");
    BibtexString tripleA = new BibtexString("AAA", "Some other #BBB#");
    BibtexString tripleB = new BibtexString("BBB", "Some more text");
    BibtexString tripleC = new BibtexString("CCC", "Even more text");
    Set<BibtexString> stringSet = new HashSet<>();
    stringSet.add(tripleA);
    stringSet.add(tripleB);
    database.addString(tripleA);
    database.addString(tripleB);
    database.addString(tripleC);
    database.insertEntry(entry);
    Set<BibtexString> usedStrings = new HashSet<>(database.getUsedStrings(Arrays.asList(entry)));
    assertEquals(stringSet, usedStrings);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibtexString(org.jabref.model.entry.BibtexString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method insertStringUpdatesStringList.

@Test
public void insertStringUpdatesStringList() {
    BibtexString string = new BibtexString("DSP", "Digital Signal Processing");
    database.addString(string);
    assertFalse(database.hasNoStrings());
    assertEquals(database.getStringKeySet().size(), 1);
    assertEquals(database.getStringCount(), 1);
    assertTrue(database.getStringValues().contains(string));
    assertTrue(database.getStringKeySet().contains(string.getId()));
    assertEquals(string, database.getString(string.getId()));
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 23 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method addSameStringIdTwiceThrowsKeyCollisionException.

@Test(expected = KeyCollisionException.class)
public void addSameStringIdTwiceThrowsKeyCollisionException() {
    BibtexString string = new BibtexString("DSP", "Digital Signal Processing");
    string.setId("duplicateid");
    database.addString(string);
    string = new BibtexString("VLSI", "Very Large Scale Integration");
    string.setId("duplicateid");
    database.addString(string);
    fail();
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 24 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method getUsedStringsSingleString.

@Test
public void getUsedStringsSingleString() {
    BibEntry entry = new BibEntry();
    entry.setField("author", "#AAA#");
    BibtexString tripleA = new BibtexString("AAA", "Some other text");
    BibtexString tripleB = new BibtexString("BBB", "Some more text");
    List<BibtexString> strings = new ArrayList<>(1);
    strings.add(tripleA);
    database.addString(tripleA);
    database.addString(tripleB);
    database.insertEntry(entry);
    List<BibtexString> usedStrings = (List<BibtexString>) database.getUsedStrings(Arrays.asList(entry));
    assertEquals(strings, usedStrings);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Example 25 with BibtexString

use of org.jabref.model.entry.BibtexString in project jabref by JabRef.

the class BibDatabaseTest method circularStringResolving.

@Test
public void circularStringResolving() {
    BibtexString string = new BibtexString("AAA", "#BBB#");
    database.addString(string);
    string = new BibtexString("BBB", "#AAA#");
    database.addString(string);
    assertEquals(database.resolveForStrings("#AAA#"), "AAA");
    assertEquals(database.resolveForStrings("#BBB#"), "BBB");
}
Also used : BibtexString(org.jabref.model.entry.BibtexString) Test(org.junit.Test)

Aggregations

BibtexString (org.jabref.model.entry.BibtexString)40 Test (org.junit.Test)24 ParserResult (org.jabref.logic.importer.ParserResult)8 BibEntry (org.jabref.model.entry.BibEntry)7 StringReader (java.io.StringReader)6 KeyCollisionException (org.jabref.model.database.KeyCollisionException)5 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 NamedCompound (org.jabref.gui.undo.NamedCompound)2 UndoableStringChange (org.jabref.gui.undo.UndoableStringChange)2 BibDatabase (org.jabref.model.database.BibDatabase)2 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Scanner (java.util.Scanner)1 Matcher (java.util.regex.Matcher)1