AdRiley commented on code in PR #920:
URL: https://github.com/apache/poi/pull/920#discussion_r2448145877
##########
poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestXSSFBReader.java:
##########
@@ -216,4 +229,234 @@ public String toString() {
return sb.toString();
}
}
+
+ private static XSSFBSheetHandler.XSSFBSheetContentsHandler
mockSheetContentsHandler() {
+ return mock(
+ XSSFBSheetHandler.XSSFBSheetContentsHandler.class,
+ withSettings().strictness(Strictness.STRICT_STUBS));
+ }
+
+ private static ArgumentMatcher<XSSFComment> commentWith(String author,
String text) {
+ return comment -> comment != null
+ && author.equals(comment.getAuthor())
+ && comment.getString() != null
+ && text.equals(comment.getString().toString().trim());
+ }
+
+ void testXSSFBSheetContentsHandler(String fileName,
+ XSSFBSheetHandler.XSSFBSheetContentsHandler handler) throws
Exception {
+ try (OPCPackage pkg =
OPCPackage.open(_ssTests.openResourceAsStream(fileName))) {
+ XSSFBReader r = new XSSFBReader(pkg);
+ assertNotNull(r.getXSSFBStylesTable());
+ XSSFBSharedStringsTable sst = new XSSFBSharedStringsTable(pkg);
+ XSSFBStylesTable xssfbStylesTable = r.getXSSFBStylesTable();
+ XSSFBReader.SheetIterator it = (XSSFBReader.SheetIterator)
r.getSheetsData();
+
+ while (it.hasNext()) {
+ InputStream is = it.next();
+ XSSFBSheetHandler sheetHandler = new XSSFBSheetHandler(is,
+ xssfbStylesTable,
+ it.getXSSFBSheetComments(),
+ sst,
+ handler,
+ false);
+ sheetHandler.parse();
+ }
+ }
+ }
+
+ @Test
+ void testBasicXSSFBSheetContentsHandler() throws Exception {
+ XSSFBSheetHandler.XSSFBSheetContentsHandler handler =
mockSheetContentsHandler();
+ testXSSFBSheetContentsHandler("testVarious.xlsb", handler);
+
+ InOrder ordered = inOrder(handler);
Review Comment:
Because I need to test that certain callbacks get called on the
XSSFBSheetContentsHandler. So I needed to either create a mock handler by hand
(which is what the existing tests did) or use a third party mocking framework
like mockito (that I think was already been used in other places in the code
base).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]