Skip to content

Commit

Permalink
Add test case for other and unknown type (#2152)
Browse files Browse the repository at this point in the history
* add test case for other and unknown type

* address comments

* move tests for reading to the parser test

* create bib entry by hand
  • Loading branch information
tschechlovdev authored and tobiasdiez committed Oct 17, 2016
1 parent 38fe410 commit 8b65bf3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/net/sf/jabref/logic/bibtex/BibEntryWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,44 @@ public void testSerialization() throws IOException {
assertEquals(expected, actual);
}

@Test
public void writeOtherTypeTest() throws Exception {
String expected = OS.NEWLINE + "@Other{test," + OS.NEWLINE +
" comment = {testentry}," + OS.NEWLINE +
"}"+ OS.NEWLINE;

BibEntry entry = new BibEntry();
entry.setType("other");
entry.setField("Comment","testentry");
entry.setCiteKey("test");

//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();

assertEquals(expected, actual);
}

@Test
public void writeReallyunknownTypeTest() throws Exception {
String expected = OS.NEWLINE + "@Reallyunknowntype{test," + OS.NEWLINE +
" comment = {testentry}," + OS.NEWLINE +
"}"+ OS.NEWLINE;

BibEntry entry = new BibEntry();
entry.setType("ReallyUnknownType");
entry.setField("Comment","testentry");
entry.setCiteKey("test");

//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();

assertEquals(expected, actual);
}

@Test
public void roundTripTest() throws IOException {
// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@ public void parseRecognizesEntryWithUnknownType() throws IOException {
assertEquals(Optional.of("Ed von Test"), e.getField("author"));
}

@Test
public void parseReallyUnknownType() throws Exception {
String bibtexEntry = "@ReallyUnknownType{test," + OS.NEWLINE +
" Comment = {testentry}" + OS.NEWLINE +
"}";

Collection<BibEntry> entries = new BibtexParser(importFormatPreferences).parseEntries(bibtexEntry);

BibEntry expectedEntry = new BibEntry();
expectedEntry.setType("Reallyunknowntype");
expectedEntry.setCiteKey("test");
expectedEntry.setField("comment", "testentry");

assertEquals(Collections.singletonList(expectedEntry), entries);
}

@Test
public void parseOtherTypeTest() throws Exception {
String bibtexEntry = "@Other{test," + OS.NEWLINE +
" Comment = {testentry}" + OS.NEWLINE +
"}";

Collection<BibEntry> entries = new BibtexParser(importFormatPreferences).parseEntries(bibtexEntry);

BibEntry expectedEntry = new BibEntry();
expectedEntry.setType("Other");
expectedEntry.setCiteKey("test");
expectedEntry.setField("comment", "testentry");

assertEquals(Collections.singletonList(expectedEntry), entries);
}

@Test
public void parseRecognizesEntryWithVeryLongType() throws IOException {

Expand Down

0 comments on commit 8b65bf3

Please sign in to comment.