/** fill the given LabelPattern by values generated from the text fields */
  private void fillPatternUsingPanelData(AbstractBibtexKeyPattern keypatterns) {
    // each entry type
    for (Map.Entry<String, JTextField> entry : textFields.entrySet()) {
      String text = entry.getValue().getText();
      if (!text.trim().isEmpty()) {
        keypatterns.addBibtexKeyPattern(entry.getKey(), text);
      }
    }

    // default value
    String text = defaultPat.getText();
    if (!text.trim()
        .isEmpty()) { // we do not trim the value at the assignment to enable users to have spaces
      // at the beginning and at the end of the pattern
      keypatterns.setDefaultValue(text);
    }
  }
  @Test
  public void writeCustomKeyPattern() throws Exception {
    AbstractBibtexKeyPattern pattern = new DatabaseBibtexKeyPattern(prefs.getKeyPattern());
    pattern.setDefaultValue("test");
    pattern.addBibtexKeyPattern("article", "articleTest");
    metaData.setCiteKeyPattern(pattern);

    StringSaveSession session =
        databaseWriter.savePartOfDatabase(
            bibtexContext, Collections.emptyList(), new SavePreferences());

    assertEquals(
        OS.NEWLINE
            + "@Comment{jabref-meta: keypattern_article:articleTest;}"
            + OS.NEWLINE
            + OS.NEWLINE
            + "@Comment{jabref-meta: keypatterndefault:test;}"
            + OS.NEWLINE,
        session.getStringValue());
  }