### Question:
PubMedListFormat extends Format { @Override public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { if (!(obj instanceof List<?>)) { throw new IllegalArgumentException(); } List<?> list = (List<?>) obj; if(list.size() >= 1) { toAppendTo.append(list.get(0)); for (int i = 1; i < list.size(); i++) { toAppendTo.append(", "); toAppendTo.append(list.get(i)); } } return toAppendTo; }  @Override StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos); @Override Object parseObject(String source, ParsePosition pos);  }### Answer:
@Test public void testFormatEmptyList() { assertEquals("", d_format.format(Collections.emptyList())); }
@Test(expected=IllegalArgumentException.class) public void testNonListShouldThrow() { d_format.format("X"); }
@Test public void testFormatSingleEntry() { String str1 = "12345"; assertEquals(str1, d_format.format(Collections.singletonList(new PubMedId(str1)))); String str2 = "123456"; assertEquals(str2, d_format.format(Collections.singletonList(new PubMedId(str2)))); }
@Test public void testFormatMultipleEntry() { String str1 = "123"; String str2 = "456"; List<PubMedId> lst = new ArrayList<PubMedId>(); lst.add(new PubMedId(str1)); lst.add(new PubMedId(str2)); assertEquals(str1 + ", " + str2, d_format.format(lst)); }