refactor(api): replace FQNs with proper imports (#1206)
This commit is contained in:
@@ -39,6 +39,7 @@ import java.util.Set;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@@ -237,12 +238,12 @@ class AppBookServiceFilterOptionsTest {
|
||||
when(magicShelfBookService.toSpecification(eq(userId), eq(magicShelfId)))
|
||||
.thenReturn(mockSpec);
|
||||
|
||||
jakarta.persistence.criteria.Predicate mockPredicate = mock(jakarta.persistence.criteria.Predicate.class);
|
||||
Predicate mockPredicate = mock(Predicate.class);
|
||||
CriteriaBuilder cb = mock(CriteriaBuilder.class);
|
||||
CriteriaQuery<Long> cq = mock(CriteriaQuery.class);
|
||||
Root<BookEntity> root = mock(Root.class);
|
||||
Path<Long> idPath = mock(Path.class);
|
||||
jakarta.persistence.TypedQuery<Long> typedQuery = mock(jakarta.persistence.TypedQuery.class);
|
||||
TypedQuery<Long> typedQuery = mock(TypedQuery.class);
|
||||
|
||||
when(entityManager.getCriteriaBuilder()).thenReturn(cb);
|
||||
when(cb.createQuery(Long.class)).thenReturn(cq);
|
||||
|
||||
@@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OidcAuthServiceTest {
|
||||
@@ -60,7 +61,7 @@ class OidcAuthServiceTest {
|
||||
var field = OidcAuthService.class.getDeclaredField("userLocks");
|
||||
field.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
var locks = (java.util.concurrent.ConcurrentMap<String, ?>) field.get(null);
|
||||
var locks = (ConcurrentMap<String, ?>) field.get(null);
|
||||
locks.clear();
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -41,6 +41,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AuthenticationServiceTest {
|
||||
@@ -193,7 +194,7 @@ class AuthenticationServiceTest {
|
||||
verify(refreshTokenRepository).save(refreshTokenCaptor.capture());
|
||||
RefreshTokenEntity saved = refreshTokenCaptor.getValue();
|
||||
Instant expectedExpiry = before.plusMillis(customExpirationMs);
|
||||
assertThat(saved.getExpiryDate()).isCloseTo(expectedExpiry, within(5, java.time.temporal.ChronoUnit.SECONDS));
|
||||
assertThat(saved.getExpiryDate()).isCloseTo(expectedExpiry, within(5, ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,7 +214,7 @@ class AuthenticationServiceTest {
|
||||
verify(refreshTokenRepository).save(refreshTokenCaptor.capture());
|
||||
RefreshTokenEntity saved = refreshTokenCaptor.getValue();
|
||||
Instant expectedExpiry = before.plusMillis(JwtUtils.refreshTokenExpirationMs);
|
||||
assertThat(saved.getExpiryDate()).isCloseTo(expectedExpiry, within(5, java.time.temporal.ChronoUnit.SECONDS));
|
||||
assertThat(saved.getExpiryDate()).isCloseTo(expectedExpiry, within(5, ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.time.temporal.ChronoUnit;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OidcSessionCleanupServiceTest {
|
||||
@@ -63,7 +64,7 @@ class OidcSessionCleanupServiceTest {
|
||||
oidcSessionCleanupService.cleanupOidcSessions();
|
||||
|
||||
InOrder inOrder = inOrder(oidcSessionRepository);
|
||||
inOrder.verify(oidcSessionRepository).deleteByRevokedTrueAndCreatedAtBefore(org.mockito.ArgumentMatchers.any(Instant.class));
|
||||
inOrder.verify(oidcSessionRepository).deleteByCreatedAtBefore(org.mockito.ArgumentMatchers.any(Instant.class));
|
||||
inOrder.verify(oidcSessionRepository).deleteByRevokedTrueAndCreatedAtBefore(ArgumentMatchers.any(Instant.class));
|
||||
inOrder.verify(oidcSessionRepository).deleteByCreatedAtBefore(ArgumentMatchers.any(Instant.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class BookMetadataMapperTest {
|
||||
@@ -29,14 +33,14 @@ public class BookMetadataMapperTest {
|
||||
|
||||
private BookMetadataMapperImpl bookMetadataMapper;
|
||||
|
||||
@org.junit.jupiter.api.BeforeEach
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
bookMetadataMapper = new BookMetadataMapperImpl();
|
||||
org.springframework.test.util.ReflectionTestUtils.setField(bookMetadataMapper, "authorMapper", authorMapper);
|
||||
org.springframework.test.util.ReflectionTestUtils.setField(bookMetadataMapper, "categoryMapper", categoryMapper);
|
||||
org.springframework.test.util.ReflectionTestUtils.setField(bookMetadataMapper, "moodMapper", moodMapper);
|
||||
org.springframework.test.util.ReflectionTestUtils.setField(bookMetadataMapper, "tagMapper", tagMapper);
|
||||
org.springframework.test.util.ReflectionTestUtils.setField(bookMetadataMapper, "comicMetadataMapper", comicMetadataMapper);
|
||||
ReflectionTestUtils.setField(bookMetadataMapper, "authorMapper", authorMapper);
|
||||
ReflectionTestUtils.setField(bookMetadataMapper, "categoryMapper", categoryMapper);
|
||||
ReflectionTestUtils.setField(bookMetadataMapper, "moodMapper", moodMapper);
|
||||
ReflectionTestUtils.setField(bookMetadataMapper, "tagMapper", tagMapper);
|
||||
ReflectionTestUtils.setField(bookMetadataMapper, "comicMetadataMapper", comicMetadataMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,10 +50,10 @@ public class BookMetadataMapperTest {
|
||||
entity.setHardcoverId("hc-id");
|
||||
entity.setHardcoverRating(4.5);
|
||||
entity.setGoodreadsId("gr-id");
|
||||
entity.setAuthors(new java.util.ArrayList<>());
|
||||
entity.setCategories(new java.util.HashSet<>());
|
||||
entity.setMoods(new java.util.HashSet<>());
|
||||
entity.setTags(new java.util.HashSet<>());
|
||||
entity.setAuthors(new ArrayList<>());
|
||||
entity.setCategories(new HashSet<>());
|
||||
entity.setMoods(new HashSet<>());
|
||||
entity.setTags(new HashSet<>());
|
||||
|
||||
BookMetadata dto = bookMetadataMapper.toBookMetadata(entity);
|
||||
|
||||
|
||||
@@ -401,8 +401,8 @@ class BookAdditionalFileRepositoryTest {
|
||||
|
||||
Throwable current = thrown;
|
||||
while (current != null) {
|
||||
if (current instanceof org.hibernate.exception.ConstraintViolationException ||
|
||||
current instanceof java.sql.SQLIntegrityConstraintViolationException ||
|
||||
if (current instanceof ConstraintViolationException ||
|
||||
current instanceof SQLIntegrityConstraintViolationException ||
|
||||
current.getClass().getName().contains("ConstraintViolation")) {
|
||||
isConstraintViolation = true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ class BookOpdsRepositoryDataJpaTest {
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
@TestConfiguration
|
||||
public static class TestConfig {
|
||||
@Bean("flyway")
|
||||
@Primary
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
|
||||
@SpringBootTest(classes = {
|
||||
BookloreApplication.class
|
||||
@@ -57,7 +58,7 @@ class BookRepositoryDataJpaTest {
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
@TestConfiguration
|
||||
public static class TestConfig {
|
||||
@Bean("flyway")
|
||||
@Primary
|
||||
|
||||
@@ -130,7 +130,7 @@ class BookMarkServiceTest {
|
||||
when(bookMarkRepository.existsByCfiAndBookIdAndUserId("new-cfi", bookId, userId)).thenReturn(false); // No duplicate
|
||||
when(bookRepository.findById(bookId)).thenReturn(Optional.empty()); // Book doesn't exist
|
||||
|
||||
assertThrows(jakarta.persistence.EntityNotFoundException.class, () -> bookMarkService.createBookmark(request));
|
||||
assertThrows(EntityNotFoundException.class, () -> bookMarkService.createBookmark(request));
|
||||
verify(bookMarkRepository, never()).save(any());
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Map;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import org.flywaydb.core.Flyway;
|
||||
|
||||
@SpringBootTest(classes = {BookloreApplication.class})
|
||||
@Transactional
|
||||
@@ -58,8 +59,8 @@ class BookRuleEvaluatorEdgeCasesTest {
|
||||
static class TestConfig {
|
||||
@Bean("flyway")
|
||||
@Primary
|
||||
public org.flywaydb.core.Flyway flyway() {
|
||||
return mock(org.flywaydb.core.Flyway.class);
|
||||
public Flyway flyway() {
|
||||
return mock(Flyway.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -1111,11 +1111,11 @@ class BookRuleEvaluatorFieldCoverageTest {
|
||||
@Test
|
||||
void withinLast_weeks_matchesRecentBook() {
|
||||
BookEntity recent = createBook("Recent Book");
|
||||
recent.setAddedOn(Instant.now().minus(5, java.time.temporal.ChronoUnit.DAYS));
|
||||
recent.setAddedOn(Instant.now().minus(5, ChronoUnit.DAYS));
|
||||
em.merge(recent);
|
||||
|
||||
BookEntity old = createBook("Old Book");
|
||||
old.setAddedOn(Instant.now().minus(30, java.time.temporal.ChronoUnit.DAYS));
|
||||
old.setAddedOn(Instant.now().minus(30, ChronoUnit.DAYS));
|
||||
em.merge(old);
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1128,11 +1128,11 @@ class BookRuleEvaluatorFieldCoverageTest {
|
||||
@Test
|
||||
void olderThan_weeks_matchesOldBook() {
|
||||
BookEntity old = createBook("Old Book");
|
||||
old.setAddedOn(Instant.now().minus(30, java.time.temporal.ChronoUnit.DAYS));
|
||||
old.setAddedOn(Instant.now().minus(30, ChronoUnit.DAYS));
|
||||
em.merge(old);
|
||||
|
||||
BookEntity recent = createBook("Recent Book");
|
||||
recent.setAddedOn(Instant.now().minus(3, java.time.temporal.ChronoUnit.DAYS));
|
||||
recent.setAddedOn(Instant.now().minus(3, ChronoUnit.DAYS));
|
||||
em.merge(recent);
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1383,12 +1383,12 @@ class BookRuleEvaluatorFieldCoverageTest {
|
||||
void thisPeriod_year_matchesThisYearFinished() {
|
||||
BookEntity thisYear = createBook("Recently Finished");
|
||||
UserBookProgressEntity p1 = createProgress(thisYear, ReadStatus.READ);
|
||||
p1.setDateFinished(Instant.now().minus(10, java.time.temporal.ChronoUnit.DAYS));
|
||||
p1.setDateFinished(Instant.now().minus(10, ChronoUnit.DAYS));
|
||||
em.merge(p1);
|
||||
|
||||
BookEntity lastYear = createBook("Finished Last Year");
|
||||
UserBookProgressEntity p2 = createProgress(lastYear, ReadStatus.READ);
|
||||
p2.setDateFinished(Instant.now().minus(400, java.time.temporal.ChronoUnit.DAYS));
|
||||
p2.setDateFinished(Instant.now().minus(400, ChronoUnit.DAYS));
|
||||
em.merge(p2);
|
||||
em.flush();
|
||||
em.clear();
|
||||
|
||||
+5
-2
@@ -35,6 +35,9 @@ import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
@SpringBootTest(classes = {BookloreApplication.class})
|
||||
@Transactional
|
||||
@@ -1486,10 +1489,10 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
@Test
|
||||
void thisPeriod_week_matchesThisWeekBook() {
|
||||
// Use midweek (Wednesday) of the current week to avoid boundary issues on Monday
|
||||
LocalDate thisWeekWednesday = LocalDate.now().with(java.time.temporal.TemporalAdjusters.previousOrSame(java.time.DayOfWeek.MONDAY)).plusDays(2);
|
||||
LocalDate thisWeekWednesday = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).plusDays(2);
|
||||
// If Wednesday is in the future (we're Mon/Tue), just use today
|
||||
LocalDate safeDate = thisWeekWednesday.isAfter(LocalDate.now()) ? LocalDate.now() : thisWeekWednesday;
|
||||
Instant thisWeekInstant = safeDate.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant().plus(12, ChronoUnit.HOURS);
|
||||
Instant thisWeekInstant = safeDate.atStartOfDay(ZoneId.systemDefault()).toInstant().plus(12, ChronoUnit.HOURS);
|
||||
|
||||
BookEntity thisWeekBook = createBook("This Week Book");
|
||||
thisWeekBook.setAddedOn(thisWeekInstant);
|
||||
|
||||
@@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.booklore.model.entity.BookdropFileEntity.Status.PENDING_REVIEW;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookdropMetadataServiceTest {
|
||||
@@ -93,7 +94,7 @@ class BookdropMetadataServiceTest {
|
||||
void attachInitialMetadata_shouldThrowWhenFileMissing() {
|
||||
when(bookdropFileRepository.findById(99L)).thenReturn(Optional.empty());
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () -> bookdropMetadataService.attachInitialMetadata(99L));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> bookdropMetadataService.attachInitialMetadata(99L));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -222,4 +223,4 @@ class BookdropMetadataServiceTest {
|
||||
assertThatThrownBy(() -> bookdropMetadataService.attachFetchedMetadata(1L))
|
||||
.isInstanceOf(JacksonException.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.time.Instant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import jakarta.servlet.WriteListener;
|
||||
|
||||
class FileStreamingServiceTest {
|
||||
|
||||
@@ -544,7 +545,7 @@ class FileStreamingServiceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWriteListener(jakarta.servlet.WriteListener writeListener) {
|
||||
public void setWriteListener(WriteListener writeListener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
|
||||
/**
|
||||
* Integration tests verifying Hibernate entity relationships, lazy loading,
|
||||
@@ -74,7 +76,7 @@ class HibernateRegressionTest {
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@org.springframework.boot.test.context.TestConfiguration
|
||||
@TestConfiguration
|
||||
public static class TestConfig {
|
||||
@Bean("flyway")
|
||||
@Primary
|
||||
@@ -311,7 +313,7 @@ class HibernateRegressionTest {
|
||||
// Intentionally NOT setting library back-reference
|
||||
|
||||
Assertions.assertThrows(
|
||||
org.springframework.dao.DataIntegrityViolationException.class,
|
||||
DataIntegrityViolationException.class,
|
||||
() -> {
|
||||
libraryRepository.saveAndFlush(library);
|
||||
entityManager.flush();
|
||||
|
||||
@@ -65,6 +65,7 @@ import java.util.Set;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@@ -476,7 +477,7 @@ class KoboEntitlementServiceTest {
|
||||
private BookEntity createEpubBookEntity(Long id) {
|
||||
BookEntity book = new BookEntity();
|
||||
book.setId(id);
|
||||
book.setBookFiles(new java.util.ArrayList<>());
|
||||
book.setBookFiles(new ArrayList<>());
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
.book(book)
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.stream.Stream;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.util.Optional;
|
||||
|
||||
@DisplayName("KoboReadingStateBuilder Tests")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -50,7 +51,7 @@ class KoboReadingStateBuilderTest {
|
||||
KoboSyncSettings settings = new KoboSyncSettings();
|
||||
settings.setTwoWayProgressSync(true);
|
||||
when(koboSettingsService.getCurrentUserSettings()).thenReturn(settings);
|
||||
when(bookmarkLocationResolver.resolve(any(), any(), any())).thenReturn(java.util.Optional.empty());
|
||||
when(bookmarkLocationResolver.resolve(any(), any(), any())).thenReturn(Optional.empty());
|
||||
builder = new KoboReadingStateBuilder(koboSettingsService, bookmarkLocationResolver);
|
||||
}
|
||||
|
||||
@@ -276,7 +277,7 @@ class KoboReadingStateBuilderTest {
|
||||
fileProgress.setPositionHref("OPS/chapter3.xhtml");
|
||||
|
||||
when(bookmarkLocationResolver.resolve(progress, fileProgress, null))
|
||||
.thenReturn(java.util.Optional.of(
|
||||
.thenReturn(Optional.of(
|
||||
new KoboBookmarkLocationResolver.ResolvedBookmarkLocation(
|
||||
"kobo.12.18",
|
||||
"KoboSpan",
|
||||
|
||||
@@ -28,6 +28,8 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.Optional;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* Integration tests that feed a real RAR5 archive into the service layer
|
||||
@@ -63,11 +65,11 @@ class Rar5IntegrationTest {
|
||||
|
||||
BookEntity book = new BookEntity();
|
||||
book.setId(99L);
|
||||
BookRepository mockRepo = org.mockito.Mockito.mock(BookRepository.class);
|
||||
org.mockito.Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(java.util.Optional.of(book));
|
||||
ChapterCacheService mockCache = org.mockito.Mockito.mock(ChapterCacheService.class);
|
||||
BookRepository mockRepo = Mockito.mock(BookRepository.class);
|
||||
Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(Optional.of(book));
|
||||
ChapterCacheService mockCache = Mockito.mock(ChapterCacheService.class);
|
||||
|
||||
try (var fileUtilsStatic = org.mockito.Mockito.mockStatic(FileUtils.class)) {
|
||||
try (var fileUtilsStatic = Mockito.mockStatic(FileUtils.class)) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(book))
|
||||
.thenReturn(cbrCopy);
|
||||
|
||||
@@ -86,12 +88,12 @@ class Rar5IntegrationTest {
|
||||
|
||||
BookEntity book = new BookEntity();
|
||||
book.setId(99L);
|
||||
BookRepository mockRepo = org.mockito.Mockito.mock(BookRepository.class);
|
||||
org.mockito.Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(java.util.Optional.of(book));
|
||||
ChapterCacheService mockCache = org.mockito.Mockito.mock(ChapterCacheService.class);
|
||||
BookRepository mockRepo = Mockito.mock(BookRepository.class);
|
||||
Mockito.when(mockRepo.findByIdForStreaming(99L)).thenReturn(Optional.of(book));
|
||||
ChapterCacheService mockCache = Mockito.mock(ChapterCacheService.class);
|
||||
|
||||
try (
|
||||
var fileUtilsStatic = org.mockito.Mockito.mockStatic(FileUtils.class)
|
||||
var fileUtilsStatic = Mockito.mockStatic(FileUtils.class)
|
||||
) {
|
||||
fileUtilsStatic.when(() -> FileUtils.getBookFullPath(book))
|
||||
.thenReturn(cbrCopy);
|
||||
@@ -145,7 +147,7 @@ class Rar5IntegrationTest {
|
||||
Path cbrCopy = tempDir.resolve("test.cbr");
|
||||
Files.copy(RAR5_CBR, cbrCopy);
|
||||
|
||||
AppSettingService mockSettings = org.mockito.Mockito.mock(AppSettingService.class);
|
||||
AppSettingService mockSettings = Mockito.mock(AppSettingService.class);
|
||||
var appSettings = new AppSettings();
|
||||
var persistenceSettings = new MetadataPersistenceSettings();
|
||||
var saveToFile = new MetadataPersistenceSettings.SaveToOriginalFile();
|
||||
@@ -155,7 +157,7 @@ class Rar5IntegrationTest {
|
||||
saveToFile.setCbx(cbxSettings);
|
||||
persistenceSettings.setSaveToOriginalFile(saveToFile);
|
||||
appSettings.setMetadataPersistenceSettings(persistenceSettings);
|
||||
org.mockito.Mockito.when(mockSettings.getAppSettings()).thenReturn(appSettings);
|
||||
Mockito.when(mockSettings.getAppSettings()).thenReturn(appSettings);
|
||||
|
||||
CbxMetadataWriter writer = new CbxMetadataWriter(mockSettings, new ArchiveService());
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@@ -323,11 +324,11 @@ class BookDropServiceTest {
|
||||
|
||||
try (MockedStatic<Files> filesMock = mockStatic(Files.class, withSettings().lenient())) {
|
||||
filesMock.when(() -> Files.exists(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.walk(any(Path.class))).thenReturn(java.util.stream.Stream.of(tempDir));
|
||||
filesMock.when(() -> Files.walk(any(Path.class))).thenReturn(Stream.of(tempDir));
|
||||
filesMock.when(() -> Files.isDirectory(any(Path.class))).thenReturn(false);
|
||||
filesMock.when(() -> Files.isRegularFile(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.deleteIfExists(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.list(any(Path.class))).thenReturn(java.util.stream.Stream.empty());
|
||||
filesMock.when(() -> Files.list(any(Path.class))).thenReturn(Stream.empty());
|
||||
|
||||
bookDropService.discardSelectedFiles(true, excludedIds, null);
|
||||
|
||||
@@ -348,11 +349,11 @@ class BookDropServiceTest {
|
||||
|
||||
try (MockedStatic<Files> filesMock = mockStatic(Files.class, withSettings().lenient())) {
|
||||
filesMock.when(() -> Files.exists(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.walk(any(Path.class))).thenReturn(java.util.stream.Stream.of(tempDir));
|
||||
filesMock.when(() -> Files.walk(any(Path.class))).thenReturn(Stream.of(tempDir));
|
||||
filesMock.when(() -> Files.isDirectory(any(Path.class))).thenReturn(false);
|
||||
filesMock.when(() -> Files.isRegularFile(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.deleteIfExists(any(Path.class))).thenReturn(true);
|
||||
filesMock.when(() -> Files.list(any(Path.class))).thenReturn(java.util.stream.Stream.empty());
|
||||
filesMock.when(() -> Files.list(any(Path.class))).thenReturn(Stream.empty());
|
||||
|
||||
bookDropService.discardSelectedFiles(false, null, selectedIds);
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.function.Consumer;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@@ -53,7 +57,7 @@ class FileMoveServiceTest {
|
||||
@Mock private BookMapper bookMapper;
|
||||
@Mock private NotificationService notificationService;
|
||||
@Mock private EntityManager entityManager;
|
||||
@Mock private org.springframework.transaction.support.TransactionTemplate transactionTemplate;
|
||||
@Mock private TransactionTemplate transactionTemplate;
|
||||
@Mock private SidecarMetadataWriter sidecarMetadataWriter;
|
||||
|
||||
private FileMoveService service;
|
||||
@@ -65,7 +69,7 @@ class FileMoveServiceTest {
|
||||
LibraryRepository libraryRepository, FileMoveHelper fileMoveHelper,
|
||||
MonitoringRegistrationService monitoringRegistrationService, LibraryMapper libraryMapper,
|
||||
BookMapper bookMapper, NotificationService notificationService, EntityManager entityManager,
|
||||
org.springframework.transaction.support.TransactionTemplate transactionTemplate,
|
||||
TransactionTemplate transactionTemplate,
|
||||
SidecarMetadataWriter sidecarMetadataWriter) {
|
||||
super(appProperties, bookRepository, bookFileRepository, libraryRepository, fileMoveHelper,
|
||||
monitoringRegistrationService, libraryMapper, bookMapper, notificationService, entityManager, transactionTemplate, sidecarMetadataWriter);
|
||||
@@ -83,7 +87,7 @@ class FileMoveServiceTest {
|
||||
|
||||
// Mock simple execution for transaction template
|
||||
doAnswer(invocation -> {
|
||||
java.util.function.Consumer<org.springframework.transaction.TransactionStatus> action = invocation.getArgument(0);
|
||||
Consumer<TransactionStatus> action = invocation.getArgument(0);
|
||||
action.accept(null);
|
||||
return null;
|
||||
}).when(transactionTemplate).executeWithoutResult(any());
|
||||
@@ -1197,7 +1201,7 @@ class FileMoveServiceTest {
|
||||
move.setTargetLibraryPathId(20L);
|
||||
request.setMoves(List.of(move));
|
||||
|
||||
org.assertj.core.api.Assertions.assertThatThrownBy(() -> service.bulkMoveFiles(request))
|
||||
Assertions.assertThatThrownBy(() -> service.bulkMoveFiles(request))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("File move operations are only supported on local storage");
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.net.http.HttpHeaders;
|
||||
import java.util.List;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class KoboServerProxyTest {
|
||||
@@ -78,7 +80,7 @@ class KoboServerProxyTest {
|
||||
private void setupSuccessfulProxyResponse() throws Exception {
|
||||
when(httpResponse.statusCode()).thenReturn(200);
|
||||
when(httpResponse.body()).thenReturn("{}");
|
||||
when(httpResponse.headers()).thenReturn(java.net.http.HttpHeaders.of(
|
||||
when(httpResponse.headers()).thenReturn(HttpHeaders.of(
|
||||
Collections.emptyMap(),
|
||||
(k, v) -> true
|
||||
));
|
||||
@@ -154,8 +156,8 @@ class KoboServerProxyTest {
|
||||
when(bookloreSyncTokenGenerator.fromRequestHeaders(any())).thenReturn(mockSyncToken);
|
||||
when(httpResponse.statusCode()).thenReturn(200);
|
||||
when(httpResponse.body()).thenReturn("{}");
|
||||
when(httpResponse.headers()).thenReturn(java.net.http.HttpHeaders.of(
|
||||
Map.of(KoboHeaders.X_KOBO_SYNCTOKEN, java.util.List.of("new-kobo-token")),
|
||||
when(httpResponse.headers()).thenReturn(HttpHeaders.of(
|
||||
Map.of(KoboHeaders.X_KOBO_SYNCTOKEN, List.of("new-kobo-token")),
|
||||
(k, v) -> true
|
||||
));
|
||||
when(objectMapper.readTree(anyString())).thenReturn(mock(JsonNode.class));
|
||||
@@ -177,8 +179,8 @@ class KoboServerProxyTest {
|
||||
|
||||
when(httpResponse.statusCode()).thenReturn(200);
|
||||
when(httpResponse.body()).thenReturn("{}");
|
||||
when(httpResponse.headers()).thenReturn(java.net.http.HttpHeaders.of(
|
||||
Map.of("X-Kobo-Response", java.util.List.of("test")),
|
||||
when(httpResponse.headers()).thenReturn(HttpHeaders.of(
|
||||
Map.of("X-Kobo-Response", List.of("test")),
|
||||
(k, v) -> true
|
||||
));
|
||||
when(objectMapper.readTree(anyString())).thenReturn(mock(JsonNode.class));
|
||||
@@ -211,7 +213,7 @@ class KoboServerProxyTest {
|
||||
|
||||
when(httpResponse.statusCode()).thenReturn(400);
|
||||
when(httpResponse.body()).thenReturn("{\"error\":\"Bad Request\"}");
|
||||
when(httpResponse.headers()).thenReturn(java.net.http.HttpHeaders.of(
|
||||
when(httpResponse.headers()).thenReturn(HttpHeaders.of(
|
||||
Collections.emptyMap(),
|
||||
(k, v) -> true
|
||||
));
|
||||
|
||||
@@ -136,7 +136,7 @@ class LibraryRescanHelperTest {
|
||||
@Test
|
||||
void handleRescanOptions_shouldSkipNullBooks() {
|
||||
BookEntity book1 = createBookEntity(1L, "book1.epub", BookFileType.EPUB);
|
||||
java.util.List<BookEntity> books = new ArrayList<>();
|
||||
List<BookEntity> books = new ArrayList<>();
|
||||
books.add(book1);
|
||||
books.add(null);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookCoverServiceTest {
|
||||
@@ -442,7 +443,7 @@ class BookCoverServiceTest {
|
||||
MultipartFile file = mock(MultipartFile.class);
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
when(file.getInputStream()).thenReturn(new java.io.ByteArrayInputStream(new byte[]{1, 2, 3}));
|
||||
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[]{1, 2, 3}));
|
||||
|
||||
assertThatThrownBy(() -> service.updateCoverFromFileForBooks(Set.of(1L), file))
|
||||
.isInstanceOf(APIException.class)
|
||||
@@ -472,7 +473,7 @@ class BookCoverServiceTest {
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
try {
|
||||
when(file.getInputStream()).thenReturn(new java.io.ByteArrayInputStream(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xE0}));
|
||||
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF, (byte) 0xE0}));
|
||||
when(file.getBytes()).thenReturn(new byte[]{1, 2, 3});
|
||||
} catch (Exception _) {}
|
||||
|
||||
@@ -490,7 +491,7 @@ class BookCoverServiceTest {
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
try {
|
||||
when(file.getInputStream()).thenReturn(new java.io.ByteArrayInputStream(new byte[]{(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}));
|
||||
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[]{(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}));
|
||||
when(file.getBytes()).thenReturn(new byte[]{1, 2, 3});
|
||||
} catch (Exception _) {}
|
||||
|
||||
@@ -507,7 +508,7 @@ class BookCoverServiceTest {
|
||||
MultipartFile file = mock(MultipartFile.class);
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
when(file.getInputStream()).thenThrow(new java.io.IOException("Test error"));
|
||||
when(file.getInputStream()).thenThrow(new IOException("Test error"));
|
||||
|
||||
assertThatThrownBy(() -> service.updateCoverFromFileForBooks(Set.of(1L), file))
|
||||
.isInstanceOf(APIException.class)
|
||||
@@ -744,7 +745,7 @@ class BookCoverServiceTest {
|
||||
MultipartFile file = mock(MultipartFile.class);
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
when(file.getInputStream()).thenReturn(new java.io.ByteArrayInputStream(new byte[]{(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}));
|
||||
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[]{(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}));
|
||||
when(file.getBytes()).thenReturn(new byte[]{1, 2, 3});
|
||||
|
||||
doAnswer(inv -> {
|
||||
@@ -910,7 +911,7 @@ class BookCoverServiceTest {
|
||||
MultipartFile file = mock(MultipartFile.class);
|
||||
when(file.isEmpty()).thenReturn(false);
|
||||
when(file.getSize()).thenReturn(1024L);
|
||||
when(file.getInputStream()).thenReturn(new java.io.ByteArrayInputStream(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF}));
|
||||
when(file.getInputStream()).thenReturn(new ByteArrayInputStream(new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF}));
|
||||
when(appSettingService.getAppSettings()).thenReturn(appSettings);
|
||||
when(appSettings.getMaxFileUploadSizeInMb()).thenReturn(10);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookMetadataServiceTest {
|
||||
@@ -519,7 +520,7 @@ class BookMetadataServiceTest {
|
||||
when(bookRepository.findByIdFull(1L)).thenReturn(Optional.of(book1));
|
||||
when(bookRepository.findByIdFull(2L)).thenReturn(Optional.of(book2));
|
||||
|
||||
var txStatus = mock(org.springframework.transaction.TransactionStatus.class);
|
||||
var txStatus = mock(TransactionStatus.class);
|
||||
when(transactionManager.getTransaction(any())).thenReturn(txStatus);
|
||||
|
||||
service.bulkUpdateMetadata(request, true, false, true);
|
||||
@@ -540,7 +541,7 @@ class BookMetadataServiceTest {
|
||||
MetadataClearFlags clearFlags = new MetadataClearFlags();
|
||||
when(metadataClearFlagsMapper.toClearFlags(request)).thenReturn(clearFlags);
|
||||
|
||||
var txStatus = mock(org.springframework.transaction.TransactionStatus.class);
|
||||
var txStatus = mock(TransactionStatus.class);
|
||||
when(transactionManager.getTransaction(any())).thenReturn(txStatus);
|
||||
|
||||
BookEntity book2 = BookEntity.builder().id(2L).build();
|
||||
@@ -563,7 +564,7 @@ class BookMetadataServiceTest {
|
||||
MetadataClearFlags clearFlags = new MetadataClearFlags();
|
||||
when(metadataClearFlagsMapper.toClearFlags(request)).thenReturn(clearFlags);
|
||||
|
||||
var txStatus = mock(org.springframework.transaction.TransactionStatus.class);
|
||||
var txStatus = mock(TransactionStatus.class);
|
||||
when(transactionManager.getTransaction(any())).thenReturn(txStatus);
|
||||
|
||||
BookEntity book = BookEntity.builder().id(1L).build();
|
||||
|
||||
@@ -35,6 +35,8 @@ import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookMetadataUpdaterTest {
|
||||
@@ -627,17 +629,17 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void updateFileNameIfConverted_noChangeWhenOriginalExists() {
|
||||
BookFileEntity bookFile = BookFileEntity.builder().fileName("test.cbr").build();
|
||||
java.nio.file.Path tempDir;
|
||||
Path tempDir;
|
||||
try {
|
||||
tempDir = java.nio.file.Files.createTempDirectory("test-metadata-");
|
||||
java.nio.file.Path original = tempDir.resolve("test.cbr");
|
||||
java.nio.file.Files.createFile(original);
|
||||
tempDir = Files.createTempDirectory("test-metadata-");
|
||||
Path original = tempDir.resolve("test.cbr");
|
||||
Files.createFile(original);
|
||||
|
||||
updater.updateFileNameIfConverted(bookFile, original);
|
||||
|
||||
assertThat(bookFile.getFileName()).isEqualTo("test.cbr");
|
||||
java.nio.file.Files.deleteIfExists(original);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(original);
|
||||
Files.deleteIfExists(tempDir);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -647,16 +649,16 @@ class BookMetadataUpdaterTest {
|
||||
void updateFileNameIfConverted_updatesToCbzWhenOriginalGoneAndCbzExists() {
|
||||
BookFileEntity bookFile = BookFileEntity.builder().fileName("test.cbr").build();
|
||||
try {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-");
|
||||
java.nio.file.Path original = tempDir.resolve("test.cbr");
|
||||
java.nio.file.Path cbz = tempDir.resolve("test.cbz");
|
||||
java.nio.file.Files.createFile(cbz);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-");
|
||||
Path original = tempDir.resolve("test.cbr");
|
||||
Path cbz = tempDir.resolve("test.cbz");
|
||||
Files.createFile(cbz);
|
||||
|
||||
updater.updateFileNameIfConverted(bookFile, original);
|
||||
|
||||
assertThat(bookFile.getFileName()).isEqualTo("test.cbz");
|
||||
java.nio.file.Files.deleteIfExists(cbz);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(cbz);
|
||||
Files.deleteIfExists(tempDir);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -1814,13 +1816,13 @@ class BookMetadataUpdaterTest {
|
||||
void noChangeWhenNeitherOriginalNorCbzExists() {
|
||||
BookFileEntity bookFile = BookFileEntity.builder().fileName("test.cbr").build();
|
||||
try {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-");
|
||||
java.nio.file.Path original = tempDir.resolve("test.cbr");
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-");
|
||||
Path original = tempDir.resolve("test.cbr");
|
||||
|
||||
updater.updateFileNameIfConverted(bookFile, original);
|
||||
|
||||
assertThat(bookFile.getFileName()).isEqualTo("test.cbr");
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(tempDir);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -1830,16 +1832,16 @@ class BookMetadataUpdaterTest {
|
||||
void handlesFileNameWithNoExtension() {
|
||||
BookFileEntity bookFile = BookFileEntity.builder().fileName("testfile").build();
|
||||
try {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-");
|
||||
java.nio.file.Path original = tempDir.resolve("testfile");
|
||||
java.nio.file.Path cbz = tempDir.resolve("testfile.cbz");
|
||||
java.nio.file.Files.createFile(cbz);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-");
|
||||
Path original = tempDir.resolve("testfile");
|
||||
Path cbz = tempDir.resolve("testfile.cbz");
|
||||
Files.createFile(cbz);
|
||||
|
||||
updater.updateFileNameIfConverted(bookFile, original);
|
||||
|
||||
assertThat(bookFile.getFileName()).isEqualTo("testfile.cbz");
|
||||
java.nio.file.Files.deleteIfExists(cbz);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(cbz);
|
||||
Files.deleteIfExists(tempDir);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
+22
-17
@@ -26,6 +26,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DuckDuckGoCoverServiceTest {
|
||||
@@ -98,22 +103,22 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void tokenPattern_noMatchMeansNoResults() {
|
||||
java.util.regex.Pattern tokenPattern = java.util.regex.Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
java.util.regex.Matcher matcher = tokenPattern.matcher("no token here");
|
||||
Pattern tokenPattern = Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
Matcher matcher = tokenPattern.matcher("no token here");
|
||||
assertThat(matcher.find()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void tokenPattern_matchesValidToken() {
|
||||
java.util.regex.Pattern tokenPattern = java.util.regex.Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
java.util.regex.Matcher matcher = tokenPattern.matcher("vqd=\"12345-67890\"");
|
||||
Pattern tokenPattern = Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
Matcher matcher = tokenPattern.matcher("vqd=\"12345-67890\"");
|
||||
assertThat(matcher.find()).isTrue();
|
||||
assertThat(matcher.group(1)).isEqualTo("12345-67890");
|
||||
}
|
||||
|
||||
@Test
|
||||
void tokenPattern_doesNotMatchInvalidToken() {
|
||||
java.util.regex.Pattern tokenPattern = java.util.regex.Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
Pattern tokenPattern = Pattern.compile("vqd=\"(\\d+-\\d+)\"");
|
||||
assertThat(tokenPattern.matcher("vqd=\"abcde\"").find()).isFalse();
|
||||
assertThat(tokenPattern.matcher("vqd=\"12345\"").find()).isFalse();
|
||||
assertThat(tokenPattern.matcher("other content").find()).isFalse();
|
||||
@@ -170,7 +175,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void coverImageFiltering_removesSmallImages() {
|
||||
List<CoverImage> images = new java.util.ArrayList<>(List.of(
|
||||
List<CoverImage> images = new ArrayList<>(List.of(
|
||||
new CoverImage("url1", 200, 300, 1),
|
||||
new CoverImage("url2", 400, 600, 2),
|
||||
new CoverImage("url3", 349, 500, 3),
|
||||
@@ -186,7 +191,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void coverImageFiltering_removesWideThanTallForBooks() {
|
||||
List<CoverImage> images = new java.util.ArrayList<>(List.of(
|
||||
List<CoverImage> images = new ArrayList<>(List.of(
|
||||
new CoverImage("url1", 400, 600, 1),
|
||||
new CoverImage("url2", 600, 400, 2),
|
||||
new CoverImage("url3", 500, 500, 3)
|
||||
@@ -203,7 +208,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
var method = DuckDuckGoCoverService.class.getDeclaredMethod("isApproximatelySquare", int.class, int.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
List<CoverImage> images = new java.util.ArrayList<>(List.of(
|
||||
List<CoverImage> images = new ArrayList<>(List.of(
|
||||
new CoverImage("url1", 500, 500, 1),
|
||||
new CoverImage("url2", 500, 800, 2),
|
||||
new CoverImage("url3", 480, 520, 3)
|
||||
@@ -224,7 +229,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void siteFilteredImages_limitedToSeven() {
|
||||
List<CoverImage> images = new java.util.ArrayList<>();
|
||||
List<CoverImage> images = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
images.add(new CoverImage("url" + i, 500, 700, i));
|
||||
}
|
||||
@@ -238,7 +243,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void generalImages_limitedToTen() {
|
||||
List<CoverImage> images = new java.util.ArrayList<>();
|
||||
List<CoverImage> images = new ArrayList<>();
|
||||
for (int i = 0; i < 15; i++) {
|
||||
images.add(new CoverImage("url" + i, 500, 700, i));
|
||||
}
|
||||
@@ -257,15 +262,15 @@ class DuckDuckGoCoverServiceTest {
|
||||
new CoverImage("https://goodreads.com/img2", 500, 700, 2)
|
||||
);
|
||||
|
||||
List<CoverImage> generalImages = new java.util.ArrayList<>(List.of(
|
||||
List<CoverImage> generalImages = new ArrayList<>(List.of(
|
||||
new CoverImage("https://amazon.com/img1", 500, 700, 1),
|
||||
new CoverImage("https://other.com/img3", 500, 700, 2),
|
||||
new CoverImage("https://example.com/img4", 500, 700, 3)
|
||||
));
|
||||
|
||||
java.util.Set<String> siteUrls = siteImages.stream()
|
||||
Set<String> siteUrls = siteImages.stream()
|
||||
.map(CoverImage::getUrl)
|
||||
.collect(java.util.stream.Collectors.toSet());
|
||||
.collect(Collectors.toSet());
|
||||
generalImages.removeIf(dto -> siteUrls.contains(dto.getUrl()));
|
||||
|
||||
assertThat(generalImages).hasSize(2);
|
||||
@@ -275,7 +280,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void resultIndexing_setsSequentialIndices() {
|
||||
List<CoverImage> allImages = new java.util.ArrayList<>(List.of(
|
||||
List<CoverImage> allImages = new ArrayList<>(List.of(
|
||||
new CoverImage("url1", 500, 700, 0),
|
||||
new CoverImage("url2", 600, 800, 0),
|
||||
new CoverImage("url3", 400, 600, 0)
|
||||
@@ -293,8 +298,8 @@ class DuckDuckGoCoverServiceTest {
|
||||
|
||||
@Test
|
||||
void imagePrioritization_amazonAndGoodreadsFirst() {
|
||||
List<CoverImage> priority = new java.util.ArrayList<>();
|
||||
List<CoverImage> others = new java.util.ArrayList<>();
|
||||
List<CoverImage> priority = new ArrayList<>();
|
||||
List<CoverImage> others = new ArrayList<>();
|
||||
|
||||
List<String> links = List.of(
|
||||
"https://other.com/img1",
|
||||
@@ -312,7 +317,7 @@ class DuckDuckGoCoverServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
List<CoverImage> all = new java.util.ArrayList<>(priority);
|
||||
List<CoverImage> all = new ArrayList<>(priority);
|
||||
all.addAll(others);
|
||||
|
||||
assertThat(all.get(0).getUrl()).contains("amazon");
|
||||
|
||||
+33
-32
@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MetadataManagementServiceTest {
|
||||
@@ -217,11 +218,11 @@ class MetadataManagementServiceTest {
|
||||
when(authorRepository.save(targetAuthor)).thenReturn(targetAuthor);
|
||||
when(authorRepository.findByNameIgnoreCase("Old")).thenReturn(Optional.of(oldAuthor));
|
||||
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-");
|
||||
java.nio.file.Path subDir = tempDir.resolve("sub");
|
||||
java.nio.file.Files.createDirectories(subDir);
|
||||
java.nio.file.Path tempFile = subDir.resolve("test.epub");
|
||||
java.nio.file.Files.createFile(tempFile);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-");
|
||||
Path subDir = tempDir.resolve("sub");
|
||||
Files.createDirectories(subDir);
|
||||
Path tempFile = subDir.resolve("test.epub");
|
||||
Files.createFile(tempFile);
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
.fileName("test.epub")
|
||||
@@ -256,9 +257,9 @@ class MetadataManagementServiceTest {
|
||||
verify(writer).saveMetadataToFile(any(), eq(metadata), isNull(), isNull());
|
||||
verify(bookRepository).saveAndFlush(book);
|
||||
|
||||
java.nio.file.Files.deleteIfExists(tempFile);
|
||||
java.nio.file.Files.deleteIfExists(subDir);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(tempFile);
|
||||
Files.deleteIfExists(subDir);
|
||||
Files.deleteIfExists(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,11 +279,11 @@ class MetadataManagementServiceTest {
|
||||
when(authorRepository.save(targetAuthor)).thenReturn(targetAuthor);
|
||||
when(authorRepository.findByNameIgnoreCase("Old")).thenReturn(Optional.of(oldAuthor));
|
||||
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-move-");
|
||||
java.nio.file.Path subDir = tempDir.resolve("sub");
|
||||
java.nio.file.Files.createDirectories(subDir);
|
||||
java.nio.file.Path tempFile = subDir.resolve("test.epub");
|
||||
java.nio.file.Files.createFile(tempFile);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-move-");
|
||||
Path subDir = tempDir.resolve("sub");
|
||||
Files.createDirectories(subDir);
|
||||
Path tempFile = subDir.resolve("test.epub");
|
||||
Files.createFile(tempFile);
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
.fileName("test.epub")
|
||||
@@ -315,9 +316,9 @@ class MetadataManagementServiceTest {
|
||||
assertThat(bookFile.getFileSubPath()).isEqualTo("new/sub");
|
||||
verify(bookRepository).saveAndFlush(book);
|
||||
|
||||
java.nio.file.Files.deleteIfExists(tempFile);
|
||||
java.nio.file.Files.deleteIfExists(subDir);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(tempFile);
|
||||
Files.deleteIfExists(subDir);
|
||||
Files.deleteIfExists(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -460,11 +461,11 @@ class MetadataManagementServiceTest {
|
||||
|
||||
@Test
|
||||
void writeMetadataToFile_skipsWriterWhenNoneAvailable() throws Exception {
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-skip-");
|
||||
java.nio.file.Path subDir = tempDir.resolve("sub");
|
||||
java.nio.file.Files.createDirectories(subDir);
|
||||
java.nio.file.Path tempFile = subDir.resolve("test.epub");
|
||||
java.nio.file.Files.createFile(tempFile);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-skip-");
|
||||
Path subDir = tempDir.resolve("sub");
|
||||
Files.createDirectories(subDir);
|
||||
Path tempFile = subDir.resolve("test.epub");
|
||||
Files.createFile(tempFile);
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
.fileName("test.epub")
|
||||
@@ -492,9 +493,9 @@ class MetadataManagementServiceTest {
|
||||
|
||||
verify(bookRepository, never()).saveAndFlush(any());
|
||||
|
||||
java.nio.file.Files.deleteIfExists(tempFile);
|
||||
java.nio.file.Files.deleteIfExists(subDir);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(tempFile);
|
||||
Files.deleteIfExists(subDir);
|
||||
Files.deleteIfExists(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -514,11 +515,11 @@ class MetadataManagementServiceTest {
|
||||
when(authorRepository.save(targetAuthor)).thenReturn(targetAuthor);
|
||||
when(authorRepository.findByNameIgnoreCase("Old")).thenReturn(Optional.of(oldAuthor));
|
||||
|
||||
java.nio.file.Path tempDir = java.nio.file.Files.createTempDirectory("test-metadata-nomove-");
|
||||
java.nio.file.Path subDir = tempDir.resolve("sub");
|
||||
java.nio.file.Files.createDirectories(subDir);
|
||||
java.nio.file.Path tempFile = subDir.resolve("original.epub");
|
||||
java.nio.file.Files.createFile(tempFile);
|
||||
Path tempDir = Files.createTempDirectory("test-metadata-nomove-");
|
||||
Path subDir = tempDir.resolve("sub");
|
||||
Files.createDirectories(subDir);
|
||||
Path tempFile = subDir.resolve("original.epub");
|
||||
Files.createFile(tempFile);
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
.fileName("original.epub")
|
||||
@@ -550,9 +551,9 @@ class MetadataManagementServiceTest {
|
||||
assertThat(bookFile.getFileName()).isEqualTo("original.epub");
|
||||
verify(bookRepository, never()).saveAndFlush(any());
|
||||
|
||||
java.nio.file.Files.deleteIfExists(tempFile);
|
||||
java.nio.file.Files.deleteIfExists(subDir);
|
||||
java.nio.file.Files.deleteIfExists(tempDir);
|
||||
Files.deleteIfExists(tempFile);
|
||||
Files.deleteIfExists(subDir);
|
||||
Files.deleteIfExists(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MetadataRefreshServiceTest {
|
||||
@@ -1132,7 +1133,7 @@ class MetadataRefreshServiceTest {
|
||||
.description("Desc")
|
||||
.publisher("Pub")
|
||||
.authors(List.of("Auth"))
|
||||
.publishedDate(java.time.LocalDate.of(2020, 1, 1))
|
||||
.publishedDate(LocalDate.of(2020, 1, 1))
|
||||
.seriesName("Series")
|
||||
.seriesNumber(1.0f)
|
||||
.seriesTotal(5)
|
||||
@@ -1159,7 +1160,7 @@ class MetadataRefreshServiceTest {
|
||||
assertThat(result.getDescription()).isEqualTo("Desc");
|
||||
assertThat(result.getPublisher()).isEqualTo("Pub");
|
||||
assertThat(result.getAuthors()).containsExactly("Auth");
|
||||
assertThat(result.getPublishedDate()).isEqualTo(java.time.LocalDate.of(2020, 1, 1));
|
||||
assertThat(result.getPublishedDate()).isEqualTo(LocalDate.of(2020, 1, 1));
|
||||
assertThat(result.getSeriesName()).isEqualTo("Series");
|
||||
assertThat(result.getSeriesNumber()).isEqualTo(1f);
|
||||
assertThat(result.getSeriesTotal()).isEqualTo(5);
|
||||
@@ -1177,7 +1178,7 @@ class MetadataRefreshServiceTest {
|
||||
.description("Amazon Desc")
|
||||
.authors(List.of("Author A"))
|
||||
.publisher("Amazon Pub")
|
||||
.publishedDate(java.time.LocalDate.of(2021, 6, 15))
|
||||
.publishedDate(LocalDate.of(2021, 6, 15))
|
||||
.seriesName("Amazon Series")
|
||||
.seriesNumber(2f)
|
||||
.seriesTotal(10)
|
||||
@@ -1209,7 +1210,7 @@ class MetadataRefreshServiceTest {
|
||||
assertThat(result.getDescription()).isEqualTo("Amazon Desc");
|
||||
assertThat(result.getAuthors()).containsExactly("Author A");
|
||||
assertThat(result.getPublisher()).isEqualTo("Amazon Pub");
|
||||
assertThat(result.getPublishedDate()).isEqualTo(java.time.LocalDate.of(2021, 6, 15));
|
||||
assertThat(result.getPublishedDate()).isEqualTo(LocalDate.of(2021, 6, 15));
|
||||
assertThat(result.getSeriesName()).isEqualTo("Amazon Series");
|
||||
assertThat(result.getSeriesNumber()).isEqualTo(2f);
|
||||
assertThat(result.getSeriesTotal()).isEqualTo(10);
|
||||
|
||||
+2
-1
@@ -38,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
class EpubMetadataWriterTest {
|
||||
|
||||
@@ -692,7 +693,7 @@ class EpubMetadataWriterTest {
|
||||
zos.write(ncxContent.getBytes(StandardCharsets.UTF_8));
|
||||
zos.closeEntry();
|
||||
|
||||
String decodedCoverPath = java.net.URLDecoder.decode("cover%C3%A1.png", java.nio.charset.StandardCharsets.UTF_8);
|
||||
String decodedCoverPath = URLDecoder.decode("cover%C3%A1.png", StandardCharsets.UTF_8);
|
||||
zos.putNextEntry(new ZipEntry("OEBPS/" + decodedCoverPath));
|
||||
zos.write(coverImage);
|
||||
zos.closeEntry();
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class OidcGroupMappingServiceTest {
|
||||
@@ -415,6 +416,6 @@ class OidcGroupMappingServiceTest {
|
||||
private List<Long> parseJsonLongs(String json) {
|
||||
if (json == null || json.equals("[]")) return List.of();
|
||||
var parts = json.replace("[", "").replace("]", "").split(",");
|
||||
return java.util.Arrays.stream(parts).map(String::trim).map(Long::valueOf).toList();
|
||||
return Arrays.stream(parts).map(String::trim).map(Long::valueOf).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class CbxReaderServiceTest {
|
||||
CbxReaderService cbxReaderService;
|
||||
|
||||
@Mock
|
||||
com.github.benmanes.caffeine.cache.Cache<String, java.util.zip.ZipFile> mockZipCache;
|
||||
Cache<String, ZipFile> mockZipCache;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<Long> longCaptor;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.stream.LongStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
class TaskHistoryServiceTest {
|
||||
|
||||
@@ -278,7 +279,7 @@ class TaskHistoryServiceTest {
|
||||
|
||||
hiddenTypes.forEach(type -> {
|
||||
try {
|
||||
java.lang.reflect.Field field = TaskType.class.getDeclaredField("hiddenFromUI");
|
||||
Field field = TaskType.class.getDeclaredField("hiddenFromUI");
|
||||
field.setAccessible(true);
|
||||
field.set(type, true);
|
||||
} catch (Exception _) {
|
||||
|
||||
+7
-5
@@ -31,6 +31,8 @@ import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class BookFileTransactionalHandlerTest {
|
||||
|
||||
@@ -141,7 +143,7 @@ class BookFileTransactionalHandlerTest {
|
||||
void libraryNotFound_throws() {
|
||||
when(libraryRepository.findById(99L)).thenReturn(Optional.empty());
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertThrows(Exception.class,
|
||||
assertThrows(Exception.class,
|
||||
() -> handler.handleNewBookFile(99L, Path.of("/library/sub/test.epub")));
|
||||
}
|
||||
|
||||
@@ -158,8 +160,8 @@ class BookFileTransactionalHandlerTest {
|
||||
handler.handleNewBookFile(1L, Path.of("/library/sub/test.epub"));
|
||||
|
||||
verify(bookFilePersistenceService).save(book);
|
||||
org.assertj.core.api.Assertions.assertThat(book.getDeleted()).isFalse();
|
||||
org.assertj.core.api.Assertions.assertThat(book.getDeletedAt()).isNull();
|
||||
assertThat(book.getDeleted()).isFalse();
|
||||
assertThat(book.getDeletedAt()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,7 +192,7 @@ class BookFileTransactionalHandlerTest {
|
||||
|
||||
verify(pendingDeletionPool).cancelByPath(any());
|
||||
verify(bookFilePersistenceService).save(book);
|
||||
org.assertj.core.api.Assertions.assertThat(bookFile.getCurrentHash()).isEqualTo("hash123");
|
||||
assertThat(bookFile.getCurrentHash()).isEqualTo("hash123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -559,7 +561,7 @@ class BookFileTransactionalHandlerTest {
|
||||
void libraryNotFound_throws() {
|
||||
when(libraryRepository.findById(99L)).thenReturn(Optional.empty());
|
||||
|
||||
org.junit.jupiter.api.Assertions.assertThrows(Exception.class,
|
||||
assertThrows(Exception.class,
|
||||
() -> handler.handleNewFolderAudiobook(99L, Path.of("/library/audiobook")));
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import java.util.Comparator;
|
||||
|
||||
class LibraryFileEventProcessorTest {
|
||||
|
||||
@@ -249,7 +250,7 @@ class LibraryFileEventProcessorTest {
|
||||
verify(bookFileTransactionalHandler, never()).handleNewBookFile(anyLong(), any());
|
||||
} finally {
|
||||
try (var stream = Files.walk(outsideFolder)) {
|
||||
stream.sorted(java.util.Comparator.reverseOrder()).forEach(p -> {
|
||||
stream.sorted(Comparator.reverseOrder()).forEach(p -> {
|
||||
try { Files.deleteIfExists(p); } catch (IOException _) {}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.ArrayList;
|
||||
|
||||
class BookFileGroupingUtilsTest {
|
||||
|
||||
@@ -864,7 +865,7 @@ class BookFileGroupingUtilsTest {
|
||||
pathEntity.setId(1L);
|
||||
pathEntity.setPath("/library");
|
||||
|
||||
List<LibraryFile> files = new java.util.ArrayList<>();
|
||||
List<LibraryFile> files = new ArrayList<>();
|
||||
String[] titles = {
|
||||
"1. The Lightning Thief.m4b",
|
||||
"2. The Sea of Monsters.m4b",
|
||||
|
||||
@@ -29,6 +29,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.when;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* Test builder for creating Library-related test objects.
|
||||
@@ -196,7 +197,7 @@ public class LibraryTestBuilder {
|
||||
.id(id)
|
||||
.library(getLibraryEntity())
|
||||
.libraryPath(getLibraryEntity().getLibraryPaths().getLast())
|
||||
.addedOn(java.time.Instant.now())
|
||||
.addedOn(Instant.now())
|
||||
.metadata(metadata)
|
||||
.bookFiles(new ArrayList<>())
|
||||
.build();
|
||||
@@ -210,7 +211,7 @@ public class LibraryTestBuilder {
|
||||
.fileSizeKb(1024L)
|
||||
.initialHash(hash)
|
||||
.currentHash(hash)
|
||||
.addedOn(java.time.Instant.now())
|
||||
.addedOn(Instant.now())
|
||||
.build();
|
||||
bookEntity.getBookFiles().add(primaryFile);
|
||||
|
||||
@@ -300,7 +301,7 @@ public class LibraryTestBuilder {
|
||||
.id(id) // Simple ID generation based on index
|
||||
.library(libraryFile.getLibraryPathEntity().getLibrary())
|
||||
.libraryPath(libraryFile.getLibraryPathEntity())
|
||||
.addedOn(java.time.Instant.now())
|
||||
.addedOn(Instant.now())
|
||||
.metadata(metadata)
|
||||
.bookFiles(new ArrayList<>())
|
||||
.build();
|
||||
@@ -314,7 +315,7 @@ public class LibraryTestBuilder {
|
||||
.fileSizeKb(1024L)
|
||||
.initialHash(hash)
|
||||
.currentHash(hash)
|
||||
.addedOn(java.time.Instant.now())
|
||||
.addedOn(Instant.now())
|
||||
.build();
|
||||
bookEntity.getBookFiles().add(primaryFile);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.nio.file.Files;
|
||||
import org.grimmory.epub4j.domain.Author;
|
||||
|
||||
class EpubContentReaderTest {
|
||||
|
||||
@@ -71,7 +73,7 @@ class EpubContentReaderTest {
|
||||
private File createTestEpub(String filename, boolean withSpine) throws IOException {
|
||||
Book book = new Book();
|
||||
book.getMetadata().addTitle("Test Book");
|
||||
book.getMetadata().addAuthor(new org.grimmory.epub4j.domain.Author("Test Author"));
|
||||
book.getMetadata().addAuthor(new Author("Test Author"));
|
||||
|
||||
if (withSpine) {
|
||||
Resource chapter1 = new Resource(CHAPTER1_CONTENT.getBytes(StandardCharsets.UTF_8), "chapter1.xhtml");
|
||||
@@ -171,7 +173,7 @@ class EpubContentReaderTest {
|
||||
@Test
|
||||
void getSpineItemContent_invalidEpubFile_throwsException() throws IOException {
|
||||
File invalidFile = tempDir.resolve("invalid.epub").toFile();
|
||||
java.nio.file.Files.writeString(invalidFile.toPath(), "not an epub");
|
||||
Files.writeString(invalidFile.toPath(), "not an epub");
|
||||
|
||||
assertThrows(
|
||||
EpubContentReader.EpubReadException.class,
|
||||
|
||||
Reference in New Issue
Block a user