package net.sf.jabref.exporter;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.model.entry.BibEntry;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.StringReader;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class SaveActionsTest {

    @BeforeClass
    public static void setUpPreferences() {
        if (Globals.prefs == null) {
            Globals.prefs = JabRefPreferences.getInstance();
        }
    }

    @Test
    public void checkSaveActionsParsing() throws IOException {
        BibtexParser parser = new BibtexParser(new StringReader("@InProceedings{6055279,\n" +
                "  Title                    = {Educational session 1},\n" +
                "  Booktitle                = {Custom Integrated Circuits Conference (CICC), 2011 IEEE},\n" +
                "  Year                     = {2011},\n" +
                "  Month                    = {Sept},\n" +
                "  Pages                    = {1-7},\n" +
                "  Abstract                 = {Start of the above-titled section of the conference proceedings record.},\n" +
                "  DOI                      = {10.1109/CICC.2011.6055279},\n" +
                "  ISSN                     = {0886-5930}\n" +
                "}\n" +
                "\n" +
                "@comment{jabref-meta: saveActions:title;IdentityFormatter;}"));

        ParserResult parserResult = parser.parse();

        List<String> saveActions = parserResult.getMetaData().getData(SaveActions.META_KEY);

        assertEquals("title", saveActions.get(0));
        assertEquals("IdentityFormatter", saveActions.get(1));

        SaveActions actions = new SaveActions(parserResult.getMetaData());

        BibEntry actedUpon = actions.applySaveActions(parserResult.getDatabase().getEntries().iterator().next());

        assertEquals("Educational session 1", actedUpon.getField("title"));
    }

}

@@ -2090,10 +2090,1472 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void checkLowerCaseSaveAction() throws IOException %7B%0A        BibtexParser parser = new BibtexParser(new StringReader(%22@InProceedings%7B6055279,%5Cn%22 +%0A                %22  Title                    = %7BEducational session 1%7D,%5Cn%22 +%0A                %22  Booktitle                = %7BCustom Integrated Circuits Conference (CICC), 2011 IEEE%7D,%5Cn%22 +%0A                %22  Year                     = %7B2011%7D,%5Cn%22 +%0A                %22  Month                    = %7BSept%7D,%5Cn%22 +%0A                %22  Pages                    = %7B1-7%7D,%5Cn%22 +%0A                %22  Abstract                 = %7BStart of the above-titled section of the conference proceedings record.%7D,%5Cn%22 +%0A                %22  DOI                      = %7B10.1109/CICC.2011.6055279%7D,%5Cn%22 +%0A                %22  ISSN                     = %7B0886-5930%7D%5Cn%22 +%0A                %22%7D%5Cn%22 +%0A                %22%5Cn%22 +%0A                %22@comment%7Bjabref-meta: saveActions:title;LowerCaseChanger;%7D%22));%0A%0A        ParserResult parserResult = parser.parse();%0A%0A        List%3CString%3E saveActions = parserResult.getMetaData().getData(SaveActions.META_KEY);%0A%0A        assertEquals(%22title%22, saveActions.get(0));%0A        assertEquals(%22LowerCaseChanger%22, saveActions.get(1));%0A%0A        SaveActions actions = new SaveActions(parserResult.getMetaData());%0A%0A        BibEntry actedUpon = actions.applySaveActions(parserResult.getDatabase().getEntries().iterator().next());%0A%0A        assertEquals(%22educational session 1%22, actedUpon.getField(%22title%22));%0A    %7D%0A%0A
 %7D%0A

Add test for lower case save action