Skip to content

Commit

Permalink
Fixed error when converting comics [#516]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcpierce committed Sep 24, 2022
1 parent a0197e3 commit 5602ae8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Expand Up @@ -23,6 +23,7 @@
import static org.comixedproject.service.admin.ConfigurationService.CFG_LIBRARY_PAGE_RENAMING_RULE;

import lombok.extern.log4j.Log4j2;
import org.comixedproject.adaptors.AdaptorException;
import org.comixedproject.adaptors.comicbooks.ComicBookAdaptor;
import org.comixedproject.model.archives.ArchiveType;
import org.comixedproject.model.comicbooks.ComicBook;
Expand Down Expand Up @@ -56,12 +57,16 @@ public ComicBook process(final ComicBook comicBook) throws Exception {
ArchiveType.forValue(this.jobParameters.getString(JOB_TARGET_ARCHIVE));
final boolean removeDeletedPages =
Boolean.parseBoolean(this.jobParameters.getString(JOB_DELETE_MARKED_PAGES));
log.trace("Recreating comicBook files");
this.comicBookAdaptor.save(
comicBook,
archiveType,
removeDeletedPages,
this.configurationService.getOptionValue(CFG_LIBRARY_PAGE_RENAMING_RULE, ""));
try {
log.trace("Recreating comicBook files");
this.comicBookAdaptor.save(
comicBook,
archiveType,
removeDeletedPages,
this.configurationService.getOptionValue(CFG_LIBRARY_PAGE_RENAMING_RULE, ""));
} catch (AdaptorException error) {
log.error("Failed to recreate comic book file", error);
}
return comicBook;
}

Expand Down
Expand Up @@ -18,7 +18,9 @@

package org.comixedproject.batch.comicbooks.processors;

import static junit.framework.TestCase.*;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertSame;

import org.comixedproject.adaptors.AdaptorException;
import org.comixedproject.adaptors.comicbooks.ComicBookAdaptor;
Expand Down Expand Up @@ -77,6 +79,26 @@ public void testProcessDeleteMarkedPages() throws Exception {
.save(comicBook, TEST_TARGET_ARCHIVE, true, TEST_PAGE_RENAMING_RULE);
}

@Test
public void testProcessAdaptorExceptionOnSave() throws Exception {
Mockito.doThrow(AdaptorException.class)
.when(comicBookAdaptor)
.save(
Mockito.any(ComicBook.class),
Mockito.any(ArchiveType.class),
Mockito.anyBoolean(),
Mockito.anyString());

final ComicBook result = processor.process(comicBook);

assertNotNull(result);
assertSame(comicBook, result);

Mockito.verify(comicBook, Mockito.never()).removeDeletedPages();
Mockito.verify(comicBookAdaptor, Mockito.times(1))
.save(comicBook, TEST_TARGET_ARCHIVE, false, TEST_PAGE_RENAMING_RULE);
}

@Test
public void testProcess() throws Exception {
final ComicBook result = processor.process(comicBook);
Expand Down

0 comments on commit 5602ae8

Please sign in to comment.