-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Added initial tests for ExportFormat #1010
Changes from 1 commit
7e0bd7c
50152cc
d316463
b9bf04a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package net.sf.jabref.exporter; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.google.common.base.Charsets; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.MetaData; | ||
import net.sf.jabref.logic.journals.JournalAbbreviationLoader; | ||
import net.sf.jabref.model.database.BibDatabase; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
public class ExportFormatTest { | ||
|
||
@Before | ||
public void setUp() { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
ExportFormats.initAllExports(); | ||
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader(Globals.prefs); | ||
|
||
} | ||
|
||
@Test | ||
public void testExportingEmptyDatabaseLayoutBasedFormat() throws Exception { | ||
BibDatabase db = new BibDatabase(); | ||
Map<String, IExportFormat> exportFormats = ExportFormats.getExportFormats(); | ||
IExportFormat exportFormat = exportFormats.get("html"); | ||
try { | ||
File tmpFile = File.createTempFile("exporttest", "html"); | ||
tmpFile.deleteOnExit(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a slightly more preferable way to deal with temporary files in form of a rule, see the wiki. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary. Will be deleted after the test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sort of assumed it, but better safe than sorry. :-) Will remove. |
||
String filename = tmpFile.getCanonicalPath(); | ||
List<BibEntry> entries = Collections.emptyList(); | ||
Charset charset = Charsets.UTF_8; | ||
MetaData metaData = new MetaData(); | ||
exportFormat.performExport(db, metaData, filename, charset, entries); | ||
} catch (IOException e) { | ||
Assert.fail("Exception caught: " + e.toString() + e.getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be more readable code if you just skip the try-catch here. The tests will fail anyway if the method is terminated by an exception and we will get all the exception info we need. There is no need to explicitly build an exception string as you do here. Some code quality tools might unnecessarily complain about missing assertions, though... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I guess one can figure out some sort of assertion, such as the
generated file actually existing...
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lenhard That should be a general rule in my opinion, not to catch Exceptions ins Tests. |
||
} | ||
} | ||
|
||
@Test | ||
public void testExportingEmptyDatabaseClassBasedFormat() throws Exception { | ||
BibDatabase db = new BibDatabase(); | ||
Map<String, IExportFormat> exportFormats = ExportFormats.getExportFormats(); | ||
IExportFormat exportFormat = exportFormats.get("oocalc"); | ||
try { | ||
File tmpFile = File.createTempFile("exporttest", "oocalc"); | ||
tmpFile.deleteOnExit(); | ||
String filename = tmpFile.getCanonicalPath(); | ||
List<BibEntry> entries = Collections.emptyList(); | ||
Charset charset = Charsets.UTF_8; | ||
MetaData metaData = new MetaData(); | ||
exportFormat.performExport(db, metaData, filename, charset, entries); | ||
} catch (IOException e) { | ||
Assert.fail("Exception caught: " + e.toString() + e.getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here the try-catch can be omitted from my point of view. |
||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how strict we are, but
db
is an abbreviation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably copies that line from the exactly same code that was later
commented on. I'll fix it. :-)
Den 21 mar 2016 18:03 skrev "Tobias Diez" notifications@github.com: