@Test
 public void testDefaultConstructor() {
   BibEntry entry = new BibEntry();
   // we have to use `getType("misc")` in the case of biblatex mode
   Assert.assertEquals("misc", entry.getType());
   Assert.assertNotNull(entry.getId());
   Assert.assertNull(entry.getField("author"));
 }
Esempio n. 2
0
  @Test
  public void hasAllRequiredFieldsFail() {
    BibEntry e = new BibEntry("id", BibtexEntryTypes.ARTICLE.getName());
    e.setField("author", "abc");
    e.setField("title", "abc");
    e.setField("journal", "abc");

    TypedBibEntry typedEntry = new TypedBibEntry(e, BibDatabaseMode.BIBTEX);
    Assert.assertFalse(typedEntry.hasAllRequiredFields());
  }
 @Test
 public void testGroupAndSearchHits() {
   BibEntry be = new BibEntry();
   be.setGroupHit(true);
   Assert.assertTrue(be.isGroupHit());
   be.setGroupHit(false);
   Assert.assertFalse(be.isGroupHit());
   be.setSearchHit(true);
   Assert.assertTrue(be.isSearchHit());
   be.setSearchHit(false);
   Assert.assertFalse(be.isSearchHit());
 }
  @Test
  public void isNullOrEmptyCiteKey() {
    BibEntry e = new BibEntry("id", BibtexEntryTypes.ARTICLE);
    Assert.assertFalse(e.hasCiteKey());

    e.setField(BibEntry.KEY_FIELD, "");
    Assert.assertFalse(e.hasCiteKey());

    try {
      e.setField(BibEntry.KEY_FIELD, null);
      Assert.fail();
    } catch (NullPointerException asExpected) {

    }

    e.setField(BibEntry.KEY_FIELD, "key");
    Assert.assertTrue(e.hasCiteKey());

    e.clearField(BibEntry.KEY_FIELD);
    Assert.assertFalse(e.hasCiteKey());
  }
  @Test
  public void allFieldsPresentOr() {
    BibEntry e = new BibEntry("id", BibtexEntryTypes.ARTICLE);
    e.setField("author", "abc");
    e.setField("title", "abc");
    e.setField("journal", "abc");
    List<String> requiredFields = new ArrayList<>();

    // XOR required
    requiredFields.add("journal/year");
    Assert.assertTrue(e.allFieldsPresent(requiredFields, null));

    requiredFields.add("year/address");
    Assert.assertFalse(e.allFieldsPresent(requiredFields, null));
  }
  @Test
  public void testCiteKeyAndID() {
    BibEntry be = new BibEntry();
    Assert.assertFalse(be.hasCiteKey());
    be.setField("author", "Albert Einstein");
    be.setField(BibEntry.KEY_FIELD, "Einstein1931");
    Assert.assertTrue(be.hasCiteKey());
    Assert.assertEquals("Einstein1931", be.getCiteKey());
    Assert.assertEquals("Albert Einstein", be.getField("author"));
    be.clearField("author");
    Assert.assertNull(be.getField("author"));

    String id = IdGenerator.next();
    be.setId(id);
    Assert.assertEquals(id, be.getId());
  }
  @Test
  public void testKeywordMethods() {
    BibEntry be = BibtexParser.singleFromString("@ARTICLE{Key15, keywords = {Foo, Bar}}");

    String[] expected = {"Foo", "Bar"};
    Assert.assertArrayEquals(expected, be.getSeparatedKeywords().toArray());

    List<String> kw = be.getSeparatedKeywords();

    be.addKeyword("FooBar");
    String[] expected2 = {"Foo", "Bar", "FooBar"};
    Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray());

    be.addKeyword("FooBar");
    Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray());

    be.addKeyword("FOO");
    Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray());

    be.addKeyword("");
    Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray());

    try {
      be.addKeyword(null);
      Assert.fail();
    } catch (NullPointerException asExpected) {

    }

    BibEntry be2 = new BibEntry();
    Assert.assertTrue(be2.getSeparatedKeywords().isEmpty());
    be2.addKeyword("");
    Assert.assertTrue(be2.getSeparatedKeywords().isEmpty());
    be2.addKeywords(be.getSeparatedKeywords());
    Assert.assertArrayEquals(expected2, be2.getSeparatedKeywords().toArray());
    be2.putKeywords(kw);
    Assert.assertArrayEquals(expected, be2.getSeparatedKeywords().toArray());
  }