Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for other and unknown type #2152

Merged
merged 4 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -235,6 +235,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