From 9633a87c879f42bb7ca8a0aeeb2f7bb839794c17 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 20 Nov 2015 23:31:51 +0100 Subject: [PATCH] Used String.join and added some tests --- .../sf/jabref/model/entry/BibtexEntry.java | 8 +---- .../net/sf/jabref/model/entry/EntryUtil.java | 18 ---------- .../jabref/model/entry/BibtexEntryTests.java | 34 +++++++++++++++++++ 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java b/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java index ca87aead0de..d6dd45a16d8 100644 --- a/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java +++ b/src/main/java/net/sf/jabref/model/entry/BibtexEntry.java @@ -491,13 +491,7 @@ public void putKeywords(ArrayList keywords) { String oldValue = this.getField("keywords"); String newValue; if (!keywords.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (String keyword : keywords) { - sb.append(keyword); - sb.append(", "); - } - sb.delete(sb.length() - 2, sb.length()); - newValue = sb.toString(); + newValue = String.join(", ", keywords); } else { newValue = null; } diff --git a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java index 9483e368b15..40c9e2beb7a 100644 --- a/src/main/java/net/sf/jabref/model/entry/EntryUtil.java +++ b/src/main/java/net/sf/jabref/model/entry/EntryUtil.java @@ -62,24 +62,6 @@ public static List getRemainder(List all, List subset) { return al; } - /** - * Concatenate two String arrays - * - * @param array1 - * the first string array - * @param array2 - * the second string array - * @return The concatenation of array1 and array2 - */ - public static String[] arrayConcat(String[] array1, String[] array2) { - int len1 = array1.length; - int len2 = array2.length; - String[] union = new String[len1 + len2]; - System.arraycopy(array1, 0, union, 0, len1); - System.arraycopy(array2, 0, union, len1, len2); - return union; - } - /** * @param keywords a String of keywords * @return an ArrayList containing the keywords. An emtpy list if keywords are null or empty diff --git a/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java b/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java index a6ad6fc069a..2287ce570ab 100644 --- a/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java +++ b/src/test/java/net/sf/jabref/model/entry/BibtexEntryTests.java @@ -122,7 +122,41 @@ public void testKeywordMethods() { Assert.assertArrayEquals(expected2, be.getSeparatedKeywords().toArray()); BibtexEntry be2 = new BibtexEntry(); + Assert.assertTrue(be2.getSeparatedKeywords().isEmpty()); + be2.addKeyword(""); + Assert.assertTrue(be2.getSeparatedKeywords().isEmpty()); be2.addKeywords(be.getSeparatedKeywords()); Assert.assertArrayEquals(expected2, be2.getSeparatedKeywords().toArray()); } + + @Test + public void testGroupAndSearchHits() { + BibtexEntry be = new BibtexEntry(); + 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 testCiteKeyAndID() { + BibtexEntry be = new BibtexEntry(); + Assert.assertFalse(be.hasCiteKey()); + be.setField("author", "Albert Einstein"); + be.setField(BibtexEntry.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()); + } }