Search in sources :

Example 1 with NormalizeDateFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter in project jabref by JabRef.

the class CleanupWorkerTest method cleanupDatesConvertsToCorrectFormat.

@Test
public void cleanupDatesConvertsToCorrectFormat() {
    CleanupPreset preset = new CleanupPreset(new FieldFormatterCleanups(true, Collections.singletonList(new FieldFormatterCleanup("date", new NormalizeDateFormatter()))));
    BibEntry entry = new BibEntry();
    entry.setField("date", "01/1999");
    worker.cleanup(preset, entry);
    Assert.assertEquals(Optional.of("1999-01"), entry.getField("date"));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) NormalizeDateFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter) FieldFormatterCleanups(org.jabref.model.cleanup.FieldFormatterCleanups) FieldFormatterCleanup(org.jabref.model.cleanup.FieldFormatterCleanup) Test(org.junit.Test)

Example 2 with NormalizeDateFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter in project jabref by JabRef.

the class FieldFormatterCleanupsTest method checkMultipleSaveActionsWithMultipleFormatters.

@Test
public void checkMultipleSaveActionsWithMultipleFormatters() {
    FieldFormatterCleanups actions = new FieldFormatterCleanups(true, Cleanups.parse("pages[normalize_page_numbers,normalize_date]title[lower_case]"));
    List<FieldFormatterCleanup> formatterCleanups = actions.getConfiguredActions();
    FieldFormatterCleanup normalizePages = new FieldFormatterCleanup("pages", new NormalizePagesFormatter());
    FieldFormatterCleanup normalizeDatesInPages = new FieldFormatterCleanup("pages", new NormalizeDateFormatter());
    FieldFormatterCleanup lowerCaseTitle = new FieldFormatterCleanup("title", new LowerCaseFormatter());
    assertEquals(Arrays.asList(normalizePages, normalizeDatesInPages, lowerCaseTitle), formatterCleanups);
    actions.applySaveActions(entry);
    assertEquals(Optional.of("educational session 1"), entry.getField("title"));
    assertEquals(Optional.of("1--7"), entry.getField("pages"));
}
Also used : NormalizeDateFormatter(org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter) 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 3 with NormalizeDateFormatter

use of org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter 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)

Aggregations

NormalizeDateFormatter (org.jabref.logic.formatter.bibtexfields.NormalizeDateFormatter)3 FieldFormatterCleanup (org.jabref.model.cleanup.FieldFormatterCleanup)3 FieldFormatterCleanups (org.jabref.model.cleanup.FieldFormatterCleanups)3 Test (org.junit.Test)3 LowerCaseFormatter (org.jabref.logic.formatter.casechanger.LowerCaseFormatter)2 IdentityFormatter (org.jabref.logic.formatter.IdentityFormatter)1 NormalizePagesFormatter (org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter)1 BibEntry (org.jabref.model.entry.BibEntry)1