@Test public void testFindTableOfContentsResource_NCX_media_resource() { String tocResourceId = "foo"; Resources resources = mock(Resources.class); Resource resource = mock(Resource.class); when(resources.getByIdOrHref(tocResourceId)).thenReturn(null); when(resources.findFirstResourceByMediaType(MediatypeService.NCX)).thenReturn(resource); Resource actualResult = PackageDocumentReader.findTableOfContentsResource("foo", resources); Assert.assertEquals(resource, actualResult); Mockito.verify(resources).getByIdOrHref(tocResourceId); Mockito.verify(resources).findFirstResourceByMediaType(MediatypeService.NCX); Mockito.verifyNoMoreInteractions(resources); }
static Resource findTableOfContentsResource(String tocResourceId, Resources resources) { Resource tocResource = null; if (StringUtil.isNotBlank(tocResourceId)) { tocResource = resources.getByIdOrHref(tocResourceId); } if (tocResource != null) { return tocResource; } tocResource = resources.findFirstResourceByMediaType(MediatypeService.NCX); if (tocResource == null) { for (int i = 0; i < POSSIBLE_NCX_ITEM_IDS.length; i++) { tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i]); if (tocResource != null) { break; } tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i].toUpperCase()); if (tocResource != null) { break; } } } if (tocResource == null) { log.error("Could not find table of contents resource. Tried resource with id '" + tocResourceId + "', " + Constants.DEFAULT_TOC_ID + ", " + Constants.DEFAULT_TOC_ID.toUpperCase() + " and any NCX resource."); } return tocResource; }
PackageDocumentReader extends PackageDocumentBase { static Resource findTableOfContentsResource(String tocResourceId, Resources resources) { Resource tocResource = null; if (StringUtil.isNotBlank(tocResourceId)) { tocResource = resources.getByIdOrHref(tocResourceId); } if (tocResource != null) { return tocResource; } tocResource = resources.findFirstResourceByMediaType(MediatypeService.NCX); if (tocResource == null) { for (int i = 0; i < POSSIBLE_NCX_ITEM_IDS.length; i++) { tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i]); if (tocResource != null) { break; } tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i].toUpperCase()); if (tocResource != null) { break; } } } if (tocResource == null) { log.error("Could not find table of contents resource. Tried resource with id '" + tocResourceId + "', " + Constants.DEFAULT_TOC_ID + ", " + Constants.DEFAULT_TOC_ID.toUpperCase() + " and any NCX resource."); } return tocResource; } }
PackageDocumentReader extends PackageDocumentBase { static Resource findTableOfContentsResource(String tocResourceId, Resources resources) { Resource tocResource = null; if (StringUtil.isNotBlank(tocResourceId)) { tocResource = resources.getByIdOrHref(tocResourceId); } if (tocResource != null) { return tocResource; } tocResource = resources.findFirstResourceByMediaType(MediatypeService.NCX); if (tocResource == null) { for (int i = 0; i < POSSIBLE_NCX_ITEM_IDS.length; i++) { tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i]); if (tocResource != null) { break; } tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i].toUpperCase()); if (tocResource != null) { break; } } } if (tocResource == null) { log.error("Could not find table of contents resource. Tried resource with id '" + tocResourceId + "', " + Constants.DEFAULT_TOC_ID + ", " + Constants.DEFAULT_TOC_ID.toUpperCase() + " and any NCX resource."); } return tocResource; }  }
PackageDocumentReader extends PackageDocumentBase { static Resource findTableOfContentsResource(String tocResourceId, Resources resources) { Resource tocResource = null; if (StringUtil.isNotBlank(tocResourceId)) { tocResource = resources.getByIdOrHref(tocResourceId); } if (tocResource != null) { return tocResource; } tocResource = resources.findFirstResourceByMediaType(MediatypeService.NCX); if (tocResource == null) { for (int i = 0; i < POSSIBLE_NCX_ITEM_IDS.length; i++) { tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i]); if (tocResource != null) { break; } tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i].toUpperCase()); if (tocResource != null) { break; } } } if (tocResource == null) { log.error("Could not find table of contents resource. Tried resource with id '" + tocResourceId + "', " + Constants.DEFAULT_TOC_ID + ", " + Constants.DEFAULT_TOC_ID.toUpperCase() + " and any NCX resource."); } return tocResource; }  static void read(Resource packageResource, EpubReader epubReader, Book book, Resources resources); }
PackageDocumentReader extends PackageDocumentBase { static Resource findTableOfContentsResource(String tocResourceId, Resources resources) { Resource tocResource = null; if (StringUtil.isNotBlank(tocResourceId)) { tocResource = resources.getByIdOrHref(tocResourceId); } if (tocResource != null) { return tocResource; } tocResource = resources.findFirstResourceByMediaType(MediatypeService.NCX); if (tocResource == null) { for (int i = 0; i < POSSIBLE_NCX_ITEM_IDS.length; i++) { tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i]); if (tocResource != null) { break; } tocResource = resources.getByIdOrHref(POSSIBLE_NCX_ITEM_IDS[i].toUpperCase()); if (tocResource != null) { break; } } } if (tocResource == null) { log.error("Could not find table of contents resource. Tried resource with id '" + tocResourceId + "', " + Constants.DEFAULT_TOC_ID + ", " + Constants.DEFAULT_TOC_ID.toUpperCase() + " and any NCX resource."); } return tocResource; }  static void read(Resource packageResource, EpubReader epubReader, Book book, Resources resources);  }