refactor(api): use Path for FileUtils.getBookFullPath (#209)
* refactor(api): use `Path` for FileUtils.getBookFullPath * test: update tests for new behavior
This commit is contained in:
@@ -74,7 +74,7 @@ class Rar5FallbackIntegrationTest {
|
||||
|
||||
try (var fileUtilsStatic = org.mockito.Mockito.mockStatic(org.booklore.util.FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> org.booklore.util.FileUtils.getBookFullPath(book))
|
||||
.thenReturn(cbrCopy.toString());
|
||||
.thenReturn(cbrCopy);
|
||||
|
||||
CbxReaderService readerService = new CbxReaderService(mockRepo);
|
||||
List<Integer> pages = readerService.getAvailablePages(99L);
|
||||
@@ -96,7 +96,7 @@ class Rar5FallbackIntegrationTest {
|
||||
|
||||
try (var fileUtilsStatic = org.mockito.Mockito.mockStatic(org.booklore.util.FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> org.booklore.util.FileUtils.getBookFullPath(book))
|
||||
.thenReturn(cbrCopy.toString());
|
||||
.thenReturn(cbrCopy);
|
||||
|
||||
CbxReaderService readerService = new CbxReaderService(mockRepo);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
@@ -81,6 +81,9 @@ class BookServiceTest {
|
||||
|
||||
private BookLoreUser testUser;
|
||||
|
||||
private Path epubPath;
|
||||
private Path pdfPath;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
BookLoreUser.UserPermissions perms = new BookLoreUser.UserPermissions();
|
||||
@@ -90,6 +93,9 @@ class BookServiceTest {
|
||||
.permissions(perms)
|
||||
.assignedLibraries(List.of())
|
||||
.isDefaultPassword(false).build();
|
||||
|
||||
epubPath = Path.of("/tmp/library/book.epub");
|
||||
pdfPath = Path.of("/tmp/library/book.pdf");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +131,7 @@ class BookServiceTest {
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(testUser);
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn("/tmp/library/book.epub");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(epubPath);
|
||||
List<Book> result = bookService.getBooksByIds(Set.of(2L), false);
|
||||
|
||||
assertEquals(1, result.size());
|
||||
@@ -153,7 +159,7 @@ class BookServiceTest {
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(testUser);
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn("/tmp/library/book.pdf");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(pdfPath);
|
||||
Book result = bookService.getBook(3L, true);
|
||||
assertEquals(3L, result.getId());
|
||||
verify(bookRepository).findByIdWithBookFiles(3L);
|
||||
@@ -329,7 +335,7 @@ class BookServiceTest {
|
||||
Path path = Paths.get("/tmp/bookcontent.txt");
|
||||
Files.write(path, "hello".getBytes());
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(path.toString());
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(path);
|
||||
ResponseEntity<Resource> response = bookService.getBookContent(10L);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertArrayEquals("hello".getBytes(), response.getBody().getInputStream().readAllBytes());
|
||||
@@ -350,7 +356,7 @@ class BookServiceTest {
|
||||
entity.setId(12L);
|
||||
when(bookRepository.findByIdWithBookFiles(12L)).thenReturn(Optional.of(entity));
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn("/tmp/nonexistentfile.txt");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(Path.of("/tmp/nonexistentfile.txt"));
|
||||
assertThrows(APIException.class, () -> bookService.getBookContent(12L));
|
||||
}
|
||||
}
|
||||
@@ -476,12 +482,12 @@ class BookServiceTest {
|
||||
// `FileUtils.getBookFullPath` calls `book.getPrimaryBookFile()`.
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn("/tmp/library/book.epub");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(entity)).thenReturn(epubPath);
|
||||
|
||||
bookService.streamBookContent(15L, null, request, response);
|
||||
|
||||
verify(bookRepository).findByIdWithBookFiles(15L);
|
||||
verify(fileStreamingService).streamWithRangeSupport(eq(Paths.get("/tmp/library/book.epub")), eq("application/epub+zip"), eq(request), eq(response));
|
||||
verify(fileStreamingService).streamWithRangeSupport(eq(epubPath), eq("application/epub+zip"), eq(request), eq(response));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -122,7 +123,7 @@ class SendEmailV2ServiceTest {
|
||||
});
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn("/library/books/test-book.epub");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn(Path.of("/library/books/test-book.epub"));
|
||||
|
||||
sendEmailV2Service.emailBookQuick(10L);
|
||||
|
||||
@@ -192,7 +193,7 @@ class SendEmailV2ServiceTest {
|
||||
});
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn("/library/books/test-book.epub");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn(Path.of("/library/books/test-book.epub"));
|
||||
|
||||
sendEmailV2Service.emailBook(request);
|
||||
|
||||
@@ -225,7 +226,7 @@ class SendEmailV2ServiceTest {
|
||||
});
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsMock = mockStatic(FileUtils.class)) {
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn("/library/books/test-book.epub");
|
||||
fileUtilsMock.when(() -> FileUtils.getBookFullPath(book)).thenReturn(Path.of("/library/books/test-book.epub"));
|
||||
|
||||
sendEmailV2Service.emailBook(request);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class CbxReaderServiceTest {
|
||||
void testGetAvailablePages_CBZ_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
|
||||
|
||||
ZipArchiveEntry entry1 = new ZipArchiveEntry("1.jpg");
|
||||
ZipArchiveEntry entry2 = new ZipArchiveEntry("2.png");
|
||||
@@ -94,7 +94,7 @@ class CbxReaderServiceTest {
|
||||
void testGetAvailablePages_CBZ_Fallback_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
|
||||
|
||||
// Unicode enabled -> throws Exception
|
||||
ZipFile zipFileFail = mock(ZipFile.class);
|
||||
@@ -141,7 +141,7 @@ class CbxReaderServiceTest {
|
||||
void testStreamPageImage_CBZ_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
|
||||
|
||||
ZipArchiveEntry entry1 = new ZipArchiveEntry("1.jpg");
|
||||
Enumeration<ZipArchiveEntry> entries = Collections.enumeration(List.of(entry1));
|
||||
@@ -180,7 +180,7 @@ class CbxReaderServiceTest {
|
||||
void testGetAvailablePages_CB7_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cb7Path.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cb7Path);
|
||||
|
||||
SevenZArchiveEntry entry1 = mock(SevenZArchiveEntry.class);
|
||||
when(entry1.getName()).thenReturn("1.jpg");
|
||||
@@ -209,7 +209,7 @@ class CbxReaderServiceTest {
|
||||
void testGetAvailablePages_CBR_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbrPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbrPath);
|
||||
|
||||
FileHeader header = mock(FileHeader.class);
|
||||
when(header.isDirectory()).thenReturn(false);
|
||||
@@ -232,7 +232,7 @@ class CbxReaderServiceTest {
|
||||
void testStreamPageImage_CBR_Success() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbrPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbrPath);
|
||||
|
||||
FileHeader header = mock(FileHeader.class);
|
||||
when(header.isDirectory()).thenReturn(false);
|
||||
@@ -261,7 +261,7 @@ class CbxReaderServiceTest {
|
||||
void testStreamPageImage_PageOutOfRange_Throws() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
|
||||
|
||||
ZipArchiveEntry entry1 = new ZipArchiveEntry("1.jpg");
|
||||
Enumeration<ZipArchiveEntry> entries = Collections.enumeration(List.of(entry1));
|
||||
@@ -292,7 +292,7 @@ class CbxReaderServiceTest {
|
||||
Files.deleteIfExists(unknownPath);
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(unknownPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(unknownPath);
|
||||
|
||||
Files.createFile(unknownPath);
|
||||
Files.setLastModifiedTime(unknownPath, FileTime.fromMillis(System.currentTimeMillis()));
|
||||
@@ -305,7 +305,7 @@ class CbxReaderServiceTest {
|
||||
void testStreamPageImage_EntryNotFound_Throws() throws Exception {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(cbzPath);
|
||||
|
||||
ZipArchiveEntry entry1 = new ZipArchiveEntry("1.jpg");
|
||||
Enumeration<ZipArchiveEntry> entries = Collections.enumeration(List.of(entry1));
|
||||
|
||||
@@ -110,7 +110,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -149,7 +149,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -177,7 +177,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
byte[] chapterContent = "<html><body>Chapter 1 content</body></html>".getBytes(StandardCharsets.UTF_8);
|
||||
ZipFile zipFile = createMockZipFileWithStreamableEntry("OEBPS/chapter1.xhtml", chapterContent);
|
||||
@@ -212,7 +212,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -238,7 +238,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -264,7 +264,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
byte[] containerContent = CONTAINER_XML.getBytes(StandardCharsets.UTF_8);
|
||||
ZipFile zipFile = createMockZipFileWithStreamableEntry("META-INF/container.xml", containerContent);
|
||||
@@ -299,7 +299,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -325,7 +325,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -353,7 +353,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFileWithSizes();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -375,7 +375,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -396,7 +396,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -424,7 +424,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -453,7 +453,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
ZipFile zipFile = createMockZipFile();
|
||||
ZipFile.Builder builder = createMockZipFileBuilder(zipFile);
|
||||
@@ -494,7 +494,7 @@ class EpubReaderServiceTest {
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(bookEntity));
|
||||
|
||||
try (MockedStatic<FileUtils> fileUtilsStatic = mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath.toString());
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(bookEntity)).thenReturn(epubPath);
|
||||
|
||||
byte[] chapterContent = "<html><body>Chapter 1 content</body></html>".getBytes(StandardCharsets.UTF_8);
|
||||
ZipFile zipFile = createMockZipFileWithStreamableEntry("OEBPS/chapter1.xhtml", chapterContent);
|
||||
|
||||
@@ -42,10 +42,9 @@ class FileUtilsTest {
|
||||
|
||||
BookEntity book = createBookEntity(libraryPath, subPath, fileName);
|
||||
|
||||
String fullPath = FileUtils.getBookFullPath(book);
|
||||
Path fullPath = FileUtils.getBookFullPath(book);
|
||||
|
||||
String expected = libraryPath.resolve(subPath).resolve(fileName)
|
||||
.toString().replace("\\", "/");
|
||||
Path expected = libraryPath.resolve(subPath).resolve(fileName);
|
||||
|
||||
assertEquals(expected, fullPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user