Search in sources :

Example 11 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeEntriesSorted.

@Test
public void writeEntriesSorted() throws Exception {
    SaveOrderConfig saveOrderConfig = new SaveOrderConfig(false, new SaveOrderConfig.SortCriterion("author", false), new SaveOrderConfig.SortCriterion("year", true), new SaveOrderConfig.SortCriterion("abstract", false));
    metaData.setSaveOrderConfig(saveOrderConfig);
    BibEntry firstEntry = new BibEntry();
    firstEntry.setType(BibtexEntryTypes.ARTICLE);
    firstEntry.setField("author", "A");
    firstEntry.setField("year", "2000");
    BibEntry secondEntry = new BibEntry();
    secondEntry.setType(BibtexEntryTypes.ARTICLE);
    secondEntry.setField("author", "A");
    secondEntry.setField("year", "2010");
    BibEntry thirdEntry = new BibEntry();
    thirdEntry.setType(BibtexEntryTypes.ARTICLE);
    thirdEntry.setField("author", "B");
    thirdEntry.setField("year", "2000");
    database.insertEntry(secondEntry);
    database.insertEntry(thirdEntry);
    database.insertEntry(firstEntry);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, database.getEntries(), new SavePreferences());
    assertEquals(OS.NEWLINE + "@Article{," + OS.NEWLINE + "  author = {A}," + OS.NEWLINE + "  year   = {2000}," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Article{," + OS.NEWLINE + "  author = {A}," + OS.NEWLINE + "  year   = {2010}," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Article{," + OS.NEWLINE + "  author = {B}," + OS.NEWLINE + "  year   = {2000}," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: saveOrderConfig:specified;author;false;year;true;abstract;false;}" + OS.NEWLINE, session.getStringValue());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig) Test(org.junit.Test)

Aggregations

SaveOrderConfig (org.jabref.model.metadata.SaveOrderConfig)11 Charset (java.nio.charset.Charset)4 Test (org.junit.Test)3 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)2 GlobalBibtexKeyPattern (org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 BibtexStringComparator (org.jabref.logic.bibtex.comparator.BibtexStringComparator)1 CrossRefEntryComparator (org.jabref.logic.bibtex.comparator.CrossRefEntryComparator)1 FieldComparator (org.jabref.logic.bibtex.comparator.FieldComparator)1 IdComparator (org.jabref.logic.bibtex.comparator.IdComparator)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibEntry (org.jabref.model.entry.BibEntry)1