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

Fix exception for unlinked files #6567

Merged
merged 5 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.logic.xmp;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand All @@ -17,6 +19,7 @@
import org.jabref.model.util.DummyFileUpdateMonitor;

import com.google.common.io.Resources;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.schema.DublinCoreSchema;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -109,4 +112,16 @@ void testReadPDMetadata() throws IOException, URISyntaxException, ParseException

assertEquals(entryFromBibFile.get(), entries.get(0));
}

/**
* Tests an pdf file with metadata which has no description section.
*/
@Test
void testGetXmpMetadataWithNoDescription() throws IOException, URISyntaxException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Method method = XmpUtilReader.class.getDeclaredMethod("getXmpMetadata", PDDocument.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need reflection, the method getMetadata is implicitly caleld, you you can simple do this two lines:

   List<BibEntry> entries = XmpUtilReader.readXmp(Path.of(XmpUtilShared.class.getResource("no_description_metadata.pdf").toURI()), xmpPreferences);
        assertEquals(Collections.emptyList(), entries);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

method.setAccessible(true);
List<XMPMetadata> entries = (List<XMPMetadata>) method.invoke(XmpUtilReader.class, PDDocument.load(XmpUtilShared.class.getResource("no_description_metadata.pdf").openStream()));
method.setAccessible(false);
assertEquals(Collections.emptyList(), entries);
}
}
Binary file not shown.