示例#1
0
  public void testAutoCompleterFactory() {
    Globals.prefs = JabRefPreferences.getInstance();
    AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(AUTHOR_FIELD);
    assertTrue(autoCompleter instanceof NameFieldAutoCompleter);

    autoCompleter = AutoCompleterFactory.getFor(OTHER_FIELD);
    assertTrue(autoCompleter instanceof DefaultAutoCompleter);
  }
示例#2
0
  public void testNameFieldCompleter() {
    Globals.prefs = JabRefPreferences.getInstance();
    AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(AUTHOR_FIELD);
    for (BibtexEntry entry : getDatabase().getEntries()) {
      autoCompleter.addBibtexEntry(entry);
    }

    // tweak preferences to match test cases
    boolean oldAutocomplete = Globals.prefs.getBoolean("autoComplete");
    Globals.prefs.putBoolean("autoComplete", Boolean.TRUE);
    boolean oldAutoCompFF = Globals.prefs.getBoolean("autoCompLF");
    Globals.prefs.putBoolean("autoCompFF", Boolean.FALSE);
    boolean oldAutoCompLF = Globals.prefs.getBoolean("autoCompLF");
    Globals.prefs.putBoolean("autoCompLF", Boolean.FALSE);
    String oldACFM = Globals.prefs.get(JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE);
    Globals.prefs.put(
        JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE,
        JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE_BOTH);

    assertEquals("Kostakos, V.", autoCompleter.complete("Kostakos")[0]);
    assertEquals(2, autoCompleter.complete("Kostakos").length);
    assertEquals("Kostakos, V.", autoCompleter.complete("Kosta")[0]);
    assertEquals(2, autoCompleter.complete("Kosta").length);
    assertEquals("Kostakos, Vassilis", autoCompleter.complete("Kostakos, Va")[0]);
    assertEquals(1, autoCompleter.complete("Kostakos, Va").length);
    assertEquals("Vassilis Kostakos", autoCompleter.complete("Va")[0]);
    assertEquals(1, autoCompleter.complete("Va").length);
    assertEquals(0, autoCompleter.complete("osta").length);
    assertEquals(0, autoCompleter.complete("osta").length);

    assertEquals("Eric von Hippel", autoCompleter.complete("Eric")[0]);
    assertEquals(1, autoCompleter.complete("Eric").length);
    assertEquals("von Hippel, E.", autoCompleter.complete("von")[0]);
    assertEquals(2, autoCompleter.complete("von").length);

    assertEquals("Reagle, Jr., J. M.", autoCompleter.complete("Reagle")[0]);
    assertEquals(2, autoCompleter.complete("Reagle").length);
    assertEquals("Reagle, Jr., Joseph M.", autoCompleter.complete("Reagle, Jr., Jo")[0]);
    assertEquals(1, autoCompleter.complete("Reagle, Jr., Jo").length);
    assertEquals("Joseph M. Reagle, Jr.", autoCompleter.complete("Joseph")[0]);
    assertEquals(1, autoCompleter.complete("Joseph").length);

    assertEquals("van den Huevel, Jr., J. A.", autoCompleter.complete("van den")[0]);
    assertEquals(2, autoCompleter.complete("van den").length);
    assertEquals("Johan A van den Huevel, Jr.", autoCompleter.complete("Joh")[0]);
    assertEquals(1, autoCompleter.complete("Joh").length);

    assertEquals("Jr. Sherry, John F.", autoCompleter.complete("Jr. S")[0]);
    assertEquals(1, autoCompleter.complete("Jr.").length);
    assertEquals("Sherry, John F., J.", autoCompleter.complete("Sherry")[0]);
    assertEquals(2, autoCompleter.complete("Sherry").length);

    // restore settings
    Globals.prefs.putBoolean("autoComplete", oldAutocomplete);
    Globals.prefs.putBoolean("autoCompFF", oldAutoCompFF);
    Globals.prefs.putBoolean("autoCompLF", oldAutoCompLF);
    Globals.prefs.put(JabRefPreferences.AUTOCOMPLETE_FIRSTNAME_MODE, oldACFM);
  }
示例#3
0
 public void testCrossRefCompleter() {
   AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(CROSSREF_FIELD);
   for (BibtexEntry entry : getDatabase().getEntries()) {
     autoCompleter.addBibtexEntry(entry);
   }
   assertEquals("1102917", autoCompleter.complete("1102917")[0]);
   assertEquals(1, autoCompleter.complete("1102917").length);
   assertEquals("1102917", autoCompleter.complete("11029")[0]);
   assertEquals(1, autoCompleter.complete("11029").length);
   assertEquals(0, autoCompleter.complete("osta").length);
   assertEquals(0, autoCompleter.complete("osta").length);
 }
示例#4
0
 public void testEntireFieldCompleter() {
   AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(ENTIRE_FIELD);
   for (BibtexEntry entry : getDatabase().getEntries()) {
     autoCompleter.addBibtexEntry(entry);
   }
   assertEquals(
       "Personal Ubiquitous Comput.", autoCompleter.complete("Personal Ubiquitous Comput.")[0]);
   assertEquals(1, autoCompleter.complete("Personal Ubiquitous Comput.").length);
   assertEquals("Personal Ubiquitous Comput.", autoCompleter.complete("Pers")[0]);
   assertEquals(1, autoCompleter.complete("Pers").length);
   assertEquals(0, autoCompleter.complete("osta").length);
   assertEquals(0, autoCompleter.complete("osta").length);
 }
示例#5
0
 public void testDefaultAutoCompleter() {
   AbstractAutoCompleter autoCompleter = AutoCompleterFactory.getFor(OTHER_FIELD);
   for (BibtexEntry entry : getDatabase().getEntries()) {
     autoCompleter.addBibtexEntry(entry);
   }
   assertEquals("authentication", autoCompleter.complete("authentication")[0]);
   assertEquals(1, autoCompleter.complete("authentication").length);
   assertEquals("authentication", autoCompleter.complete("aut")[0]);
   assertEquals(
       2,
       autoCompleter.complete("aut")
           .length); // 1 for case-sensitive search, 2 for case insensitive search (Authornames
                     // also included)
   assertEquals(
       1,
       autoCompleter.complete("Aut")
           .length); // "Aut" triggers case-sensitive search, now only "Authornames" is returned
   assertEquals("context", autoCompleter.complete("con")[0]);
   assertEquals(1, autoCompleter.complete("con").length);
   assertEquals(0, autoCompleter.complete("osta").length);
   assertEquals(0, autoCompleter.complete("osta").length);
 }