コード例 #1
0
  @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());
  }