Search in sources :

Example 21 with FieldFormatterCleanups

use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkThreeSaveActionsForOneField.

@Test
public void checkThreeSaveActionsForOneField() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("title[lower_case,identity,normalize_date]"));
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    FieldFormatterCleanup identityInTitle = new FieldFormatterCleanup("title", new IdentityFormatter());
    FieldFormatterCleanup normalizeDatesInTitle = new FieldFormatterCleanup("title", new NormalizeDateFormatter());
    assertEquals(Arrays.asList(lowerCaseTitle, identityInTitle, normalizeDatesInTitle), actions.getConfiguredActions());
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
}
Also used : IdentityFormatter(org.jabref.logic.formatter.IdentityFormatter) NormalizeDateFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 22 with FieldFormatterCleanups

use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkLowerCaseSaveAction.

@Test
public void checkLowerCaseSaveAction() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("title[lower_case]"));
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    assertEquals(Collections.singletonList(lowerCaseTitle), actions.getConfiguredActions());
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 23 with FieldFormatterCleanups

use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkMultipleSaveActions.

@Test
public void checkMultipleSaveActions() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("pages[normalize_page_numbers]title[lower_case]"));
    List<FieldFormatterCleanup> formatterCleanups = actions.getConfiguredActions();
    FieldFormatterCleanup normalizePages = new FieldFormatterCleanup("pages", new NormalizePagesFormatter());
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    assertEquals(Arrays.asList(normalizePages, lowerCaseTitle), formatterCleanups);
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
    assertEquals(Optional.of("1--7"), entry.getField("pages"));
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) NormalizePagesFormatter(org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 24 with FieldFormatterCleanups

use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeSaveActions.

@Test
public void writeSaveActions() throws Exception {
    FieldFormatterCleanups saveActions = new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("title", new LowerCaseFormatter())));
    metaData.setSaveActions(saveActions);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences());
    assertEquals(OS.NEWLINE + "@Comment{jabref-meta: saveActions:enabled;" + OS.NEWLINE + "title[lower_case]" + OS.NEWLINE + ";}" + OS.NEWLINE, session.getStringValue());
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) LowerCaseFormatter(org.jabref.logic.formatter.casechanger.LowerCaseFormatter) Test(org.junit.Test)

Example 25 with FieldFormatterCleanups

use of org.jabref.model.cleanup.FieldFormatterCleanups in project jabref by JabRef.

the class FieldFormatterCleanupsTest method clearFormatterRemovesField.

@Test
public void clearFormatterRemovesField() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("mont[clear]"));
    actions.applySaveActions(entry);
    assertEquals(Optional.empty(), entry.getField("mont"));
}
Also used : FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) Test(org.junit.Test)

Aggregations

FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)26 Test (org.junit.Test)23 FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)20 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)10 BibEntry (org.jabref.model.entry.BibEntry)10 IdentityFormatter (org.jabref.logic.formatter.IdentityFormatter)3 NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)3 NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)3 StringReader (java.io.StringReader)2 CleanupActionsListModel (org.jabref.gui.cleanup.CleanupActionsListModel)2 NormalizeMonthFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter)2 ParserResult (org.jabref.logic.importer.ParserResult)2 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 ListDataEvent (javax.swing.event.ListDataEvent)1 ListDataListener (javax.swing.event.ListDataListener)1 ClearFormatter (org.jabref.logic.formatter.bibtexfields.ClearFormatter)1 HtmlToLatexFormatter (org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter)1 LatexCleanupFormatter (org.jabref.logic.formatter.bibtexfields.LatexCleanupFormatter)1 UnitsToLatexFormatter (org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter)1