<commit_before>package net.sf.jabref.exporter;

import com.google.common.base.Charsets;
import net.sf.jabref.*;
import net.sf.jabref.logic.config.SaveOrderConfig;
import net.sf.jabref.logic.labelpattern.AbstractLabelPattern;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.groups.GroupTreeNode;
import net.sf.jabref.groups.structure.*;
import net.sf.jabref.importer.ImportFormatReader;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.labelpattern.DatabaseLabelPattern;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class BibDatabaseWriterTest {

    private BibDatabaseWriter databaseWriter;
    private StringWriter stringWriter;
    private BibDatabase database;
    private MetaData metaData;
    private BibDatabaseContext bibtexContext;

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

    @Before
    public void setUp() {
        databaseWriter = new BibDatabaseWriter();
        stringWriter = new StringWriter();
        database = new BibDatabase();
        metaData = new MetaData();
        bibtexContext = new BibDatabaseContext(database, metaData, new Defaults(BibDatabaseMode.BIBTEX));
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullWriterThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(null, bibtexContext, Collections.emptyList(), mock(SavePreferences.class));
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullContextThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), null, Collections.emptyList(), new SavePreferences());
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullEntriesThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), bibtexContext, null, new SavePreferences());
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullPreferencesThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), bibtexContext, Collections.emptyList(), null);
    }

    @Test
    public void writeEncoding() throws IOException {
        SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);

        databaseWriter.writePartOfDatabase(stringWriter, bibtexContext, Collections.emptyList(), preferences);

        Assert.assertEquals("% Encoding: US-ASCII" + Globals.NEWLINE, stringWriter.toString());
    }

    @Test
    public void writePreamble() throws IOException {
        database.setPreamble("Test preamble");
<commit_msg>Disabled NPE test<commit_after>package net.sf.jabref.exporter;

import com.google.common.base.Charsets;
import net.sf.jabref.*;
import net.sf.jabref.logic.config.SaveOrderConfig;
import net.sf.jabref.logic.labelpattern.AbstractLabelPattern;
import net.sf.jabref.model.EntryTypes;
import net.sf.jabref.groups.GroupTreeNode;
import net.sf.jabref.groups.structure.*;
import net.sf.jabref.importer.ImportFormatReader;
import net.sf.jabref.importer.ParserResult;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.labelpattern.DatabaseLabelPattern;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class BibDatabaseWriterTest {

    private BibDatabaseWriter databaseWriter;
    private StringWriter stringWriter;
    private BibDatabase database;
    private MetaData metaData;
    private BibDatabaseContext bibtexContext;

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

    @Before
    public void setUp() {
        databaseWriter = new BibDatabaseWriter();
        stringWriter = new StringWriter();
        database = new BibDatabase();
        metaData = new MetaData();
        bibtexContext = new BibDatabaseContext(database, metaData, new Defaults(BibDatabaseMode.BIBTEX));
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullWriterThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(null, bibtexContext, Collections.emptyList(), mock(SavePreferences.class));
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullContextThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), null, Collections.emptyList(), new SavePreferences());
    }

    @Test(expected = NullPointerException.class)
    @Ignore
    public void writeWithNullEntriesThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), bibtexContext, null, new SavePreferences());
    }

    @Test(expected = NullPointerException.class)
    public void writeWithNullPreferencesThrowsException() throws IOException {
        databaseWriter.writePartOfDatabase(mock(Writer.class), bibtexContext, Collections.emptyList(), null);
    }

    @Test
    public void writeEncoding() throws IOException {
        SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);

        databaseWriter.writePartOfDatabase(stringWriter, bibtexContext, Collections.emptyList(), preferences);

        Assert.assertEquals("% Encoding: US-ASCII" + Globals.NEWLINE, stringWriter.toString());
    }

    @Test
    public void writePreamble() throws IOException {
        database.setPreamble("Test preamble");

{'fraction_non_alphanumeric': 0.09762900976290098, 'fraction_numerical': 0.0, 'mean_word_length': 4.661403508771929, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '980752', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1737, 'n_words': 357}