-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Copacimportertest #310
Copacimportertest #310
Conversation
Can you please have a look at https://ondemand.coverity.com/jobs/uj1ep5hu8118n66eqa61rs5ofc/results/f/4/8/9/620b152144b541f48db807c7eed9.html which indicates issues in the test class. Please close the resources with a try-with-resources block. Regarding the |
Am I assuming right that you mean something like that? @Test
public void testIsRecognizedFormatAccept() throws IOException {
CopacImporter importer = new CopacImporter();
LinkedList<String> list = new LinkedList<>();
list.add("CopacImporterTest1.txt");
list.add("CopacImporterTest2.txt");
for (String str : list) {
try (InputStream is = CopacImporterTest.class.getResourceAsStream(str)) {
Assert.assertTrue(importer.isRecognizedFormat(is));
is.close();
}
}
} |
Almost :) As you are using try-with-resources, the line |
I read somewhere that it is still recommended (by many) to keep the close(), primarily for readability/understanding I guess. Now, I haven't followed it that carefully though... |
Do you have a link for that @oscargus ? |
Maybe not. I tried to find it, but to no avail. I found something which might be what I referred to, but it didn't actually say exactly that. Rather, I found many examples without the close(). |
//CopacImporterTest3.txt is an empty file. | ||
List<BibtexEntry> entries = importer.importEntries( | ||
CopacImporterTest.class.getResourceAsStream("CopacImporterTest3.txt"), new OutputPrinterToNull()); | ||
Assert.assertEquals(0, entries.size()); |
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.
When comparing lists, it is better to do an assert that way:
Assert.assertEquals(Collections.emptyList(), entries);
Then, the message when the assertion fails is much better, as it contains the entries in the list using their toString method.
Example:
List<String> values = new LinkedList<>();
values.add("asdf");
Assert.assertEquals(Collections.emptyList(), values);
results in
Exception in thread "main" java.lang.AssertionError: expected:<[]> but was:<[asdf]>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:144)
at Test.main(Test.java:13)
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.
Do you want me to only edit the testImportEntries3()
?
Or should I create two Lists on every testImport()
and only make one Assert at the end? For example
@Test
public void testImportEntries() throws IOException {
Globals.prefs.put("defaultEncoding", "UTF8");
CopacImporter importer = new CopacImporter();
List<BibtexEntry> entries = importer.importEntries(
CopacImporterTest.class.getResourceAsStream("CopacImporterTest1.txt"), new OutputPrinterToNull());
Assert.assertEquals(1, entries.size());
BibtexEntry entry = entries.get(0);
List<String> idealValue = new LinkedList<>();
idealValue.add("The SIS project : software reuse with a natural language approach");
idealValue.add("Prechelt, Lutz and Universität Karlsruhe. Fakultät für Informatik");
idealValue.add("Interner Bericht ; Nr.2/92");
idealValue.add("1992");
idealValue.add("Karlsruhe : Universitat Karlsruhe, Fakultat fur Informatik");
idealValue.add("Edinburgh");
idealValue.add("TXT");
List<String> isValue = new LinkedList<>();
isValue.add(entry.getField("title"));
isValue.add(entry.getField("author"));
isValue.add(entry.getField("series"));
isValue.add(entry.getField("year"));
isValue.add(entry.getField("publisher"));
isValue.add(entry.getField("HL"));
isValue.add(entry.getField("documenttype"));
Assert.assertEquals(idealValue, isValue);
Assert.assertEquals(BibtexEntryTypes.BOOK, entry.getType());
}
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 meant only when checking that the size of the list should be 0. You do not get too much information that the list has size 1. It is much easier to debug when you know what values the element in the list has.
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.
Okay. Now I know what you mean. Thank you.
After I have changed testImportEntries()
to the "two list model" I got a failure. I couldn't resolve it because it was one big Message and I didn't saw my mistake.
This is why I asked before I changed the other one and pushed it.
I just realized that a few fixes I implemented when going through coverty warnings this morning (see 5b66b98) conflict with this PR. I fixed the resource leaks and the remainder of this PR is still valuable. @zellerdev To get it into master, please merge master into your branch. Sorry for the inconvenience, I'll keep my hands off the importers from now. |
ef6280f
to
a9d182b
Compare
I noticed that line 53 reads
Could you please change that string to Furthermore, could you follow the pattern "If you modify preference, use following pattern:" stated at https://github.com/JabRef/jabref/wiki/Code-Howtos#test-cases? |
I'd like to add that you should not refer to preferences via their string key, but rather via their static variable in
|
I think, it's easier for reviewing if you squash the whole commits into one commit. |
15fd434
to
f3bfd6e
Compare
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
|
||
@Test |
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 think it is slightly better to understand if you use @Test(expect=IOException.class)
instead of the thrown
construction.
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 agree. In this case, no the whole method may throw an exception and not a single line (as IMHO discussed with @bartsch-dev in another PR)
Coverage 100%. 👍 While wondering why the import source is so small, I checked the header comment http://copac.jisc.ac.uk/faq/#format to check whether there are more fields. There, I found "How do I import Copac records in reference management software? (e.g. Endnote/Zotero)" which contains "If you use Reference Manager you can use the RIS filter to import Copac records." @obraliar @mairdl @zellerdev @ayanai1 Could you please check whether RIS is really equal to Copac? Can you read each other's code and test cases and report back here? In case they are equal, I would propose to merge the importer code. |
f3bfd6e
to
41633a2
Compare
@zellerdev I can't see what you changed why in your commit. In this case, it would have been better to add another commit. Then, I can easily see, what you changed after my approval. Now, I have to review the whole commit again and I don't know what I have been approved and what not. |
I apologize for that. Because of the problems building the project I had in the past this was a routine for me. I just included the suggestions you made on the top of the class. |
Assert.assertEquals("TXT, PDF", one.getField("documenttype")); | ||
Assert.assertEquals( | ||
"Aberdeen ; Birmingham ; Edinburgh ; Trinity College Dublin ; UCL (University College London)", | ||
one.getField("HL")); |
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.
What is HL
? From the content, I would suspect it represents the location/city of the publisher. In this case it should be written to the address
field in bibtex.
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.
This implementation of CopacImporter knows the tags TI, AU, PY, PU, SE, IS, KW, NT, PD and DT. In this case Copac doesn't know what HL is. So to address this field you have to use the tag HL as field. This ressources already existed. In this case this is a test to watch whether the importer correctly handles with unknown tags.
@koppor WDYT? |
2773bf5
to
c82ff37
Compare
@@ -25,7 +25,8 @@ public void setUp() throws Exception { | |||
@Test | |||
public final void testIsNotRecognizedFormat() throws Exception { | |||
List<String> notAccept = Arrays.asList("emptyFile.xml", "IsiImporterTest1.isi", | |||
"InspecSilverPlatterImporterTest.txt", "oai2.xml", "RisImporterTest1.ris"); | |||
"CopacImporterTest1.txt", |
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.
Please fix the formatting
f5d3c41
to
c65e380
Compare
Can you please rebase on current master? |
0fd9e5a
to
73fe37a
Compare
Coverage 98,48% |
73fe37a
to
1e33511
Compare
|
||
int size = copacEntries.size(); | ||
|
||
// workaround because BibtexEntryAssert can only test 1 entry |
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.
Then provide a method in the BibtexEntryAssert class which can do this, please.
…ec file which is not comatible to Copac. Updated CopacImporterTest filter.
Using java.nio for getTestFiles(), removed InspecSilverPlatter and replaced it with another Inspec file which is not recognized by copac and added a new method for BibtexEntryAssert using InputStreams and an ImportFormat as parameter to generate to lists to compare. I hope I solved everything as expected. |
*/ | ||
public List<String> getTestFiles() throws IOException { | ||
List<String> files = new ArrayList<>(); | ||
Files.newDirectoryStream(Paths.get(FILEFORMAT_PATH)).forEach(n -> files.add(n.getFileName().toString())); |
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.
a directory stream is a resource which must be closed. use a try-with-resources construct here, please.
New PR on a new branch.
Edited Tests. No assignments. Better formatting. Cover DT (documenttype).
New Test in case an empty Text is imported.
Edit: Added the suggestions into the testfile. Checking the equality of Copac and RIS is ongoing.