Replace arrow-based author reordering with CDK drag chips and persist author sort order (#3167) (#3175)
This commit is contained in:
@@ -8,7 +8,7 @@ import org.booklore.util.PathPatternResolver;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -38,12 +38,12 @@ class PathPatternResolverTest {
|
||||
when(metadata.getAuthors()).thenReturn(null);
|
||||
} else {
|
||||
AtomicLong idCounter = new AtomicLong(1);
|
||||
LinkedHashSet<AuthorEntity> authorEntities = authors.stream().map(name -> {
|
||||
ArrayList<AuthorEntity> authorEntities = authors.stream().map(name -> {
|
||||
AuthorEntity a = new AuthorEntity();
|
||||
a.setId(idCounter.getAndIncrement());
|
||||
a.setName(name);
|
||||
return a;
|
||||
}).collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
}).collect(Collectors.toCollection(ArrayList::new));
|
||||
when(metadata.getAuthors()).thenReturn(authorEntities);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BookMetadataMapperTest {
|
||||
entity.setHardcoverId("hc-id");
|
||||
entity.setHardcoverRating(4.5);
|
||||
entity.setGoodreadsId("gr-id");
|
||||
entity.setAuthors(new java.util.HashSet<>());
|
||||
entity.setAuthors(new java.util.ArrayList<>());
|
||||
entity.setCategories(new java.util.HashSet<>());
|
||||
entity.setMoods(new java.util.HashSet<>());
|
||||
entity.setTags(new java.util.HashSet<>());
|
||||
|
||||
@@ -463,7 +463,7 @@ class MobileSeriesServiceTest {
|
||||
.seriesName(seriesName)
|
||||
.seriesNumber(seriesNumber)
|
||||
.coverUpdatedOn(Instant.now())
|
||||
.authors(Set.of(author))
|
||||
.authors(List.of(author))
|
||||
.build();
|
||||
|
||||
BookFileEntity bookFile = BookFileEntity.builder()
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.booklore.model.entity;
|
||||
|
||||
import org.booklore.util.BookUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class BookMetadataEntityTest {
|
||||
@@ -12,7 +12,7 @@ class BookMetadataEntityTest {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("Jo Nesbø Book");
|
||||
metadata.setSubtitle("Murder Mystery");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
|
||||
metadata.updateSearchText();
|
||||
|
||||
@@ -27,7 +27,7 @@ class BookMetadataEntityTest {
|
||||
void updateSearchText_normalizesAuthorWithDiacritics() {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("The Snowman");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
|
||||
metadata.updateSearchText();
|
||||
|
||||
@@ -44,7 +44,7 @@ class BookMetadataEntityTest {
|
||||
metadata.setTitle("Müller's Café");
|
||||
metadata.setSubtitle("À la française");
|
||||
metadata.setSeriesName("José's Stories");
|
||||
metadata.setAuthors(Set.of(
|
||||
metadata.setAuthors(List.of(
|
||||
AuthorEntity.builder().name("François Müller").build(),
|
||||
AuthorEntity.builder().name("José García").build()
|
||||
));
|
||||
@@ -160,7 +160,7 @@ class BookMetadataEntityTest {
|
||||
void searchSimulation_withDiacritics() {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("The Bat");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
metadata.updateSearchText();
|
||||
|
||||
String storedSearchText = metadata.getSearchText();
|
||||
|
||||
+14
-14
@@ -1031,13 +1031,13 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity book1 = createBook("Mistborn");
|
||||
AuthorEntity author1 = AuthorEntity.builder().name("Brandon Sanderson").build();
|
||||
em.persist(author1);
|
||||
book1.getMetadata().setAuthors(new HashSet<>(Set.of(author1)));
|
||||
book1.getMetadata().setAuthors(new ArrayList<>(List.of(author1)));
|
||||
em.merge(book1.getMetadata());
|
||||
|
||||
BookEntity book2 = createBook("It");
|
||||
AuthorEntity author2 = AuthorEntity.builder().name("Stephen King").build();
|
||||
em.persist(author2);
|
||||
book2.getMetadata().setAuthors(new HashSet<>(Set.of(author2)));
|
||||
book2.getMetadata().setAuthors(new ArrayList<>(List.of(author2)));
|
||||
em.merge(book2.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1089,7 +1089,7 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity withAuthors = createBook("With Authors Book");
|
||||
AuthorEntity author = AuthorEntity.builder().name("Test Author").build();
|
||||
em.persist(author);
|
||||
withAuthors.getMetadata().setAuthors(new HashSet<>(Set.of(author)));
|
||||
withAuthors.getMetadata().setAuthors(new ArrayList<>(List.of(author)));
|
||||
em.merge(withAuthors.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1106,7 +1106,7 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity withAuthors = createBook("With Authors Book");
|
||||
AuthorEntity author = AuthorEntity.builder().name("Test Author 2").build();
|
||||
em.persist(author);
|
||||
withAuthors.getMetadata().setAuthors(new HashSet<>(Set.of(author)));
|
||||
withAuthors.getMetadata().setAuthors(new ArrayList<>(List.of(author)));
|
||||
em.merge(withAuthors.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1160,19 +1160,19 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity bookA = createBook("Book A");
|
||||
AuthorEntity authorA = AuthorEntity.builder().name("Author A").build();
|
||||
em.persist(authorA);
|
||||
bookA.getMetadata().setAuthors(new HashSet<>(Set.of(authorA)));
|
||||
bookA.getMetadata().setAuthors(new ArrayList<>(List.of(authorA)));
|
||||
em.merge(bookA.getMetadata());
|
||||
|
||||
BookEntity bookB = createBook("Book B");
|
||||
AuthorEntity authorB = AuthorEntity.builder().name("Author B").build();
|
||||
em.persist(authorB);
|
||||
bookB.getMetadata().setAuthors(new HashSet<>(Set.of(authorB)));
|
||||
bookB.getMetadata().setAuthors(new ArrayList<>(List.of(authorB)));
|
||||
em.merge(bookB.getMetadata());
|
||||
|
||||
BookEntity bookC = createBook("Book C");
|
||||
AuthorEntity authorC = AuthorEntity.builder().name("Author C").build();
|
||||
em.persist(authorC);
|
||||
bookC.getMetadata().setAuthors(new HashSet<>(Set.of(authorC)));
|
||||
bookC.getMetadata().setAuthors(new ArrayList<>(List.of(authorC)));
|
||||
em.merge(bookC.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1187,19 +1187,19 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity bookA = createBook("Book A2");
|
||||
AuthorEntity authorA = AuthorEntity.builder().name("Author A2").build();
|
||||
em.persist(authorA);
|
||||
bookA.getMetadata().setAuthors(new HashSet<>(Set.of(authorA)));
|
||||
bookA.getMetadata().setAuthors(new ArrayList<>(List.of(authorA)));
|
||||
em.merge(bookA.getMetadata());
|
||||
|
||||
BookEntity bookB = createBook("Book B2");
|
||||
AuthorEntity authorB = AuthorEntity.builder().name("Author B2").build();
|
||||
em.persist(authorB);
|
||||
bookB.getMetadata().setAuthors(new HashSet<>(Set.of(authorB)));
|
||||
bookB.getMetadata().setAuthors(new ArrayList<>(List.of(authorB)));
|
||||
em.merge(bookB.getMetadata());
|
||||
|
||||
BookEntity bookC = createBook("Book C2");
|
||||
AuthorEntity authorC = AuthorEntity.builder().name("Author C2").build();
|
||||
em.persist(authorC);
|
||||
bookC.getMetadata().setAuthors(new HashSet<>(Set.of(authorC)));
|
||||
bookC.getMetadata().setAuthors(new ArrayList<>(List.of(authorC)));
|
||||
em.merge(bookC.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1216,13 +1216,13 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
AuthorEntity authorY = AuthorEntity.builder().name("Author Y").build();
|
||||
em.persist(authorX);
|
||||
em.persist(authorY);
|
||||
bookBoth.getMetadata().setAuthors(new HashSet<>(Set.of(authorX, authorY)));
|
||||
bookBoth.getMetadata().setAuthors(new ArrayList<>(List.of(authorX, authorY)));
|
||||
em.merge(bookBoth.getMetadata());
|
||||
|
||||
BookEntity bookOne = createBook("Book One Author");
|
||||
AuthorEntity authorX2 = AuthorEntity.builder().name("Author X2").build();
|
||||
em.persist(authorX2);
|
||||
bookOne.getMetadata().setAuthors(new HashSet<>(Set.of(authorX2)));
|
||||
bookOne.getMetadata().setAuthors(new ArrayList<>(List.of(authorX2)));
|
||||
em.merge(bookOne.getMetadata());
|
||||
em.flush();
|
||||
em.clear();
|
||||
@@ -1598,7 +1598,7 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity withAuthors = createBook("With Authors");
|
||||
AuthorEntity author = AuthorEntity.builder().name("Test Author MP").build();
|
||||
em.persist(author);
|
||||
withAuthors.getMetadata().setAuthors(new HashSet<>(Set.of(author)));
|
||||
withAuthors.getMetadata().setAuthors(new ArrayList<>(List.of(author)));
|
||||
em.merge(withAuthors.getMetadata());
|
||||
|
||||
BookEntity noAuthors = createBook("No Authors");
|
||||
@@ -1615,7 +1615,7 @@ class BookRuleEvaluatorServiceIntegrationTest {
|
||||
BookEntity withAuthors = createBook("With Authors");
|
||||
AuthorEntity author = AuthorEntity.builder().name("Test Author MP2").build();
|
||||
em.persist(author);
|
||||
withAuthors.getMetadata().setAuthors(new HashSet<>(Set.of(author)));
|
||||
withAuthors.getMetadata().setAuthors(new ArrayList<>(List.of(author)));
|
||||
em.merge(withAuthors.getMetadata());
|
||||
|
||||
BookEntity noAuthors = createBook("No Authors");
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -173,7 +175,7 @@ class BookCreatorServiceTest {
|
||||
@Test
|
||||
void addAuthorsToBook_existingAuthorsOnEntity_appendsWithoutOverwriting() {
|
||||
AuthorEntity existingAuthor = AuthorEntity.builder().name("Existing").build();
|
||||
bookEntity.getMetadata().setAuthors(new HashSet<>(Set.of(existingAuthor)));
|
||||
bookEntity.getMetadata().setAuthors(new ArrayList<>(List.of(existingAuthor)));
|
||||
|
||||
AuthorEntity newAuthor = AuthorEntity.builder().name("New Author").build();
|
||||
when(authorRepository.findByName("New Author")).thenReturn(Optional.of(newAuthor));
|
||||
|
||||
+4
-4
@@ -61,7 +61,7 @@ class DuplicateDetectionServiceTest {
|
||||
.bookType(fileType)
|
||||
.build();
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>();
|
||||
List<AuthorEntity> authors = new ArrayList<>();
|
||||
if (authorName != null) {
|
||||
authors.add(AuthorEntity.builder().id(id * 10).name(authorName).build());
|
||||
}
|
||||
@@ -388,9 +388,9 @@ class DuplicateDetectionServiceTest {
|
||||
@Test
|
||||
void skipsBooksWithNoAuthors() {
|
||||
BookEntity book1 = createBook(BookFileType.EPUB, "Orphan Book", null);
|
||||
book1.getMetadata().setAuthors(new HashSet<>());
|
||||
book1.getMetadata().setAuthors(new ArrayList<>());
|
||||
BookEntity book2 = createBook(BookFileType.MOBI, "Orphan Book", null);
|
||||
book2.getMetadata().setAuthors(new HashSet<>());
|
||||
book2.getMetadata().setAuthors(new ArrayList<>());
|
||||
stubBooks(book1, book2);
|
||||
|
||||
List<DuplicateGroup> result = service.findDuplicates(onlyTitleAuthor());
|
||||
@@ -438,7 +438,7 @@ class DuplicateDetectionServiceTest {
|
||||
void requiresAtLeastTwoBooksWithAuthorsInTitleGroup() {
|
||||
BookEntity book1 = createBook(BookFileType.EPUB, "Solo Title", "Author A");
|
||||
BookEntity book2 = createBook(BookFileType.MOBI, "Solo Title", null);
|
||||
book2.getMetadata().setAuthors(new HashSet<>());
|
||||
book2.getMetadata().setAuthors(new ArrayList<>());
|
||||
stubBooks(book1, book2);
|
||||
|
||||
List<DuplicateGroup> result = service.findDuplicates(onlyTitleAuthor());
|
||||
|
||||
+4
-4
@@ -87,7 +87,7 @@ class BookdropBulkEditServiceTest {
|
||||
@Test
|
||||
void bulkEdit_WithArrayFieldsMergeMode_ShouldMergeArrays() {
|
||||
BookMetadata existingMetadata = new BookMetadata();
|
||||
existingMetadata.setAuthors(new LinkedHashSet<>(List.of("Author 1")));
|
||||
existingMetadata.setAuthors(new ArrayList<>(List.of("Author 1")));
|
||||
existingMetadata.setCategories(new LinkedHashSet<>(List.of("Category 1")));
|
||||
|
||||
when(metadataHelper.getCurrentMetadata(any())).thenReturn(existingMetadata);
|
||||
@@ -100,7 +100,7 @@ class BookdropBulkEditServiceTest {
|
||||
.thenReturn(List.of(file));
|
||||
|
||||
BookMetadata updates = new BookMetadata();
|
||||
updates.setAuthors(new LinkedHashSet<>(List.of("Author 2")));
|
||||
updates.setAuthors(new ArrayList<>(List.of("Author 2")));
|
||||
updates.setCategories(new LinkedHashSet<>(List.of("Category 2")));
|
||||
|
||||
BookdropBulkEditRequest request = new BookdropBulkEditRequest();
|
||||
@@ -129,7 +129,7 @@ class BookdropBulkEditServiceTest {
|
||||
@Test
|
||||
void bulkEdit_WithArrayFieldsReplaceMode_ShouldReplaceArrays() {
|
||||
BookMetadata existingMetadata = new BookMetadata();
|
||||
existingMetadata.setAuthors(new LinkedHashSet<>(List.of("Author 1")));
|
||||
existingMetadata.setAuthors(new ArrayList<>(List.of("Author 1")));
|
||||
|
||||
when(metadataHelper.getCurrentMetadata(any())).thenReturn(existingMetadata);
|
||||
|
||||
@@ -141,7 +141,7 @@ class BookdropBulkEditServiceTest {
|
||||
.thenReturn(List.of(file));
|
||||
|
||||
BookMetadata updates = new BookMetadata();
|
||||
updates.setAuthors(new LinkedHashSet<>(List.of("Author 2")));
|
||||
updates.setAuthors(new ArrayList<>(List.of("Author 2")));
|
||||
|
||||
BookdropBulkEditRequest request = new BookdropBulkEditRequest();
|
||||
request.setFields(updates);
|
||||
|
||||
+6
-6
@@ -83,7 +83,7 @@ class FilenamePatternExtractorTest {
|
||||
BookMetadata result = extractor.extractFromFilename(filename, pattern);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(Set.of("John Smith"), result.getAuthors());
|
||||
assertEquals(List.of("John Smith"), result.getAuthors());
|
||||
assertEquals("The Lost City", result.getTitle());
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ class FilenamePatternExtractorTest {
|
||||
assertEquals("Chronicles of Earth", result.getSeriesName());
|
||||
assertEquals(7.0f, result.getSeriesNumber());
|
||||
assertEquals("The Final Battle", result.getTitle());
|
||||
assertEquals(Set.of("John Smith"), result.getAuthors());
|
||||
assertEquals(List.of("John Smith"), result.getAuthors());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,7 +299,7 @@ class FilenamePatternExtractorTest {
|
||||
BookMetadata result = extractor.extractFromFilename(filename, pattern);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(Set.of("John Smith"), result.getAuthors());
|
||||
assertEquals(List.of("John Smith"), result.getAuthors());
|
||||
assertEquals("The Lost City", result.getTitle());
|
||||
assertEquals(1949, result.getPublishedDate().getYear());
|
||||
}
|
||||
@@ -312,7 +312,7 @@ class FilenamePatternExtractorTest {
|
||||
BookMetadata result = extractor.extractFromFilename(filename, pattern);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(Set.of("Smith", "John R."), result.getAuthors());
|
||||
assertEquals(List.of("Smith", "John R."), result.getAuthors());
|
||||
assertEquals("The Lost City", result.getTitle());
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ class FilenamePatternExtractorTest {
|
||||
assertEquals("Chronicles of Earth", result.getSeriesName());
|
||||
assertEquals(1.0f, result.getSeriesNumber());
|
||||
assertEquals("The Beginning", result.getTitle());
|
||||
assertEquals(Set.of("John Smith"), result.getAuthors());
|
||||
assertEquals(List.of("John Smith"), result.getAuthors());
|
||||
}
|
||||
|
||||
// ===== New Placeholder Tests =====
|
||||
@@ -666,7 +666,7 @@ class FilenamePatternExtractorTest {
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals("The Lost City", result.getTitle());
|
||||
assertEquals(Set.of("John Smith"), result.getAuthors());
|
||||
assertEquals(List.of("John Smith"), result.getAuthors());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -360,7 +360,7 @@ class BookCoverServiceTest {
|
||||
void generatesCoverWithTitleAndAuthor() {
|
||||
BookEntity book = buildBook(1L, false);
|
||||
AuthorEntity author = AuthorEntity.builder().name("Jane Doe").build();
|
||||
book.getMetadata().setAuthors(Set.of(author));
|
||||
book.getMetadata().setAuthors(List.of(author));
|
||||
book.setBookFiles(new ArrayList<>());
|
||||
when(bookRepository.findById(1L)).thenReturn(Optional.of(book));
|
||||
when(coverImageGenerator.generateCover("Test Book", "Jane Doe")).thenReturn(new byte[]{1, 2, 3});
|
||||
@@ -598,7 +598,7 @@ class BookCoverServiceTest {
|
||||
void successfullyGeneratesCustomAudiobookCover() {
|
||||
BookEntity book = buildBookWithAudiobookLock(1L, false);
|
||||
AuthorEntity author = AuthorEntity.builder().name("Author Name").build();
|
||||
book.getMetadata().setAuthors(Set.of(author));
|
||||
book.getMetadata().setAuthors(List.of(author));
|
||||
when(bookRepository.findByIdWithBookFiles(1L)).thenReturn(Optional.of(book));
|
||||
when(coverImageGenerator.generateSquareCover("Test Audiobook", "Author Name")).thenReturn(new byte[]{1, 2});
|
||||
when(bookRepository.findCoverUpdateInfoByIds(any())).thenReturn(List.of());
|
||||
@@ -986,7 +986,7 @@ class BookCoverServiceTest {
|
||||
@Test
|
||||
void returnsNullForEmptyAuthors() {
|
||||
BookEntity book = buildBook(1L, false);
|
||||
book.getMetadata().setAuthors(new HashSet<>());
|
||||
book.getMetadata().setAuthors(new ArrayList<>());
|
||||
when(bookRepository.findById(1L)).thenReturn(Optional.of(book));
|
||||
when(coverImageGenerator.generateCover("Test Book", null)).thenReturn(new byte[]{1});
|
||||
when(bookRepository.findCoverUpdateInfoByIds(any())).thenReturn(List.of());
|
||||
@@ -999,7 +999,7 @@ class BookCoverServiceTest {
|
||||
@Test
|
||||
void joinsMultipleAuthorNames() {
|
||||
BookEntity book = buildBook(1L, false);
|
||||
Set<AuthorEntity> authors = new LinkedHashSet<>();
|
||||
List<AuthorEntity> authors = new ArrayList<>();
|
||||
authors.add(AuthorEntity.builder().name("Alice").build());
|
||||
authors.add(AuthorEntity.builder().name("Bob").build());
|
||||
book.getMetadata().setAuthors(authors);
|
||||
|
||||
+16
-16
@@ -67,7 +67,7 @@ class BookMetadataUpdaterTest {
|
||||
metadataEntity = BookMetadataEntity.builder()
|
||||
.bookId(1L)
|
||||
.title("Original Title")
|
||||
.authors(new HashSet<>())
|
||||
.authors(new ArrayList<>())
|
||||
.categories(new HashSet<>())
|
||||
.moods(new HashSet<>())
|
||||
.tags(new HashSet<>())
|
||||
@@ -331,12 +331,12 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void setBookMetadata_authorsReplaceAll_replacesExisting() {
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Old Author").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
AuthorEntity newAuthor = AuthorEntity.builder().id(2L).name("New Author").build();
|
||||
when(authorRepository.findByName("New Author")).thenReturn(Optional.of(newAuthor));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("New Author")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("New Author")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_ALL);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -351,9 +351,9 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void setBookMetadata_authorsReplaceMissing_skipsWhenExistingAuthorsPresent() {
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Existing").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("New Author")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("New Author")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_MISSING);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -367,11 +367,11 @@ class BookMetadataUpdaterTest {
|
||||
|
||||
@Test
|
||||
void setBookMetadata_authorsReplaceMissing_addsWhenEmpty() {
|
||||
metadataEntity.setAuthors(new HashSet<>());
|
||||
metadataEntity.setAuthors(new ArrayList<>());
|
||||
AuthorEntity newAuthor = AuthorEntity.builder().id(2L).name("New").build();
|
||||
when(authorRepository.findByName("New")).thenReturn(Optional.of(newAuthor));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("New")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("New")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_MISSING);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -387,9 +387,9 @@ class BookMetadataUpdaterTest {
|
||||
void setBookMetadata_authorsLocked_notUpdated() {
|
||||
metadataEntity.setAuthorsLocked(true);
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Locked").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("New Author")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("New Author")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_ALL);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -404,7 +404,7 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void setBookMetadata_clearAuthors_clearsSet() {
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Author").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").build();
|
||||
MetadataClearFlags clearFlags = new MetadataClearFlags();
|
||||
@@ -528,9 +528,9 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void setBookMetadata_authorsReplaceAll_emptyNewAuthors_clearsExisting() {
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Author").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of()).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of()).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_ALL);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -544,12 +544,12 @@ class BookMetadataUpdaterTest {
|
||||
|
||||
@Test
|
||||
void setBookMetadata_createsNewAuthorWhenNotFound() {
|
||||
metadataEntity.setAuthors(new HashSet<>());
|
||||
metadataEntity.setAuthors(new ArrayList<>());
|
||||
AuthorEntity created = AuthorEntity.builder().id(5L).name("Brand New").build();
|
||||
when(authorRepository.findByName("Brand New")).thenReturn(Optional.empty());
|
||||
when(authorRepository.save(any(AuthorEntity.class))).thenReturn(created);
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("Brand New")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("Brand New")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, MetadataReplaceMode.REPLACE_ALL);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
@@ -1460,12 +1460,12 @@ class BookMetadataUpdaterTest {
|
||||
@Test
|
||||
void authors_nullReplaceMode_noMerge_replacesExisting() {
|
||||
AuthorEntity existing = AuthorEntity.builder().id(1L).name("Old").build();
|
||||
metadataEntity.setAuthors(new HashSet<>(Set.of(existing)));
|
||||
metadataEntity.setAuthors(new ArrayList<>(List.of(existing)));
|
||||
|
||||
AuthorEntity newAuthor = AuthorEntity.builder().id(2L).name("New").build();
|
||||
when(authorRepository.findByName("New")).thenReturn(Optional.of(newAuthor));
|
||||
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(Set.of("New")).build();
|
||||
BookMetadata newMeta = BookMetadata.builder().title("T").authors(List.of("New")).build();
|
||||
MetadataUpdateContext context = buildContext(newMeta, null);
|
||||
|
||||
try (MockedStatic<MetadataChangeDetector> mcd = mockStatic(MetadataChangeDetector.class)) {
|
||||
|
||||
+6
-6
@@ -65,7 +65,7 @@ class MetadataManagementServiceTest {
|
||||
when(authorRepository.save(targetAuthor)).thenReturn(targetAuthor);
|
||||
when(authorRepository.findByNameIgnoreCase("Old Author")).thenReturn(Optional.of(oldAuthor));
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>(List.of(oldAuthor));
|
||||
List<AuthorEntity> authors = new ArrayList<>(List.of(oldAuthor));
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder().authors(authors).build();
|
||||
when(bookMetadataRepository.findAllByAuthorsContaining(oldAuthor)).thenReturn(List.of(metadata));
|
||||
|
||||
@@ -86,7 +86,7 @@ class MetadataManagementServiceTest {
|
||||
when(authorRepository.save(any(AuthorEntity.class))).thenReturn(newAuthor);
|
||||
when(authorRepository.findByNameIgnoreCase("Old")).thenReturn(Optional.of(oldAuthor));
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>(List.of(oldAuthor));
|
||||
List<AuthorEntity> authors = new ArrayList<>(List.of(oldAuthor));
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder().authors(authors).build();
|
||||
when(bookMetadataRepository.findAllByAuthorsContaining(oldAuthor)).thenReturn(List.of(metadata));
|
||||
|
||||
@@ -234,7 +234,7 @@ class MetadataManagementServiceTest {
|
||||
.libraryPath(libraryPath)
|
||||
.build();
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder()
|
||||
.authors(new HashSet<>(List.of(oldAuthor)))
|
||||
.authors(new ArrayList<>(List.of(oldAuthor)))
|
||||
.book(book)
|
||||
.build();
|
||||
book.setMetadata(metadata);
|
||||
@@ -295,7 +295,7 @@ class MetadataManagementServiceTest {
|
||||
.libraryPath(libraryPath)
|
||||
.build();
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder()
|
||||
.authors(new HashSet<>(List.of(oldAuthor)))
|
||||
.authors(new ArrayList<>(List.of(oldAuthor)))
|
||||
.book(book)
|
||||
.build();
|
||||
book.setMetadata(metadata);
|
||||
@@ -322,7 +322,7 @@ class MetadataManagementServiceTest {
|
||||
AuthorEntity author = AuthorEntity.builder().id(1L).name("Author1").build();
|
||||
when(authorRepository.findByName("Author1")).thenReturn(Optional.of(author));
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>(List.of(author));
|
||||
List<AuthorEntity> authors = new ArrayList<>(List.of(author));
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder().authors(authors).build();
|
||||
when(bookMetadataRepository.findAllByAuthorsContaining(author)).thenReturn(List.of(metadata));
|
||||
|
||||
@@ -531,7 +531,7 @@ class MetadataManagementServiceTest {
|
||||
.libraryPath(libraryPath)
|
||||
.build();
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder()
|
||||
.authors(new HashSet<>(List.of(oldAuthor)))
|
||||
.authors(new ArrayList<>(List.of(oldAuthor)))
|
||||
.book(book)
|
||||
.build();
|
||||
book.setMetadata(metadata);
|
||||
|
||||
+5
-4
@@ -18,6 +18,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -153,7 +154,7 @@ class MetadataMatchServiceTest {
|
||||
BookMetadataEntity metadata = BookMetadataEntity.builder()
|
||||
.title("Title")
|
||||
.description("Desc")
|
||||
.authors(Set.of(AuthorEntity.builder().name("Author").build()))
|
||||
.authors(List.of(AuthorEntity.builder().name("Author").build()))
|
||||
.build();
|
||||
BookEntity book = bookWith(metadata);
|
||||
|
||||
@@ -171,7 +172,7 @@ class MetadataMatchServiceTest {
|
||||
.title("Title")
|
||||
.subtitle("Subtitle")
|
||||
.description("Description")
|
||||
.authors(Set.of(AuthorEntity.builder().name("Author").build()))
|
||||
.authors(List.of(AuthorEntity.builder().name("Author").build()))
|
||||
.publisher("Publisher")
|
||||
.publishedDate(LocalDate.now())
|
||||
.seriesName("Series")
|
||||
@@ -261,7 +262,7 @@ class MetadataMatchServiceTest {
|
||||
.build();
|
||||
stubWeights(weights);
|
||||
|
||||
BookEntity book = bookWith(BookMetadataEntity.builder().authors(new HashSet<>()).build());
|
||||
BookEntity book = bookWith(BookMetadataEntity.builder().authors(new ArrayList<>()).build());
|
||||
assertThat(service.calculateMatchScore(book)).isEqualTo(0f);
|
||||
}
|
||||
}
|
||||
@@ -367,7 +368,7 @@ class MetadataMatchServiceTest {
|
||||
stubWeights(weights);
|
||||
|
||||
BookEntity book = bookWith(BookMetadataEntity.builder()
|
||||
.authors(new HashSet<>())
|
||||
.authors(new ArrayList<>())
|
||||
.authorsLocked(true)
|
||||
.build());
|
||||
|
||||
|
||||
+4
-4
@@ -587,7 +587,7 @@ class MetadataRefreshServiceTest {
|
||||
@Test
|
||||
void resolveFieldAsList_returnsNullWhenFieldProviderNull() {
|
||||
Map<MetadataProvider, BookMetadata> metadataMap = new HashMap<>();
|
||||
Set<String> result = service.resolveFieldAsList(metadataMap, null, BookMetadata::getCategories);
|
||||
List<String> result = service.resolveFieldAsList(metadataMap, null, BookMetadata::getCategories);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@@ -602,7 +602,7 @@ class MetadataRefreshServiceTest {
|
||||
.p2(MetadataProvider.Google)
|
||||
.build();
|
||||
|
||||
Set<String> result = service.resolveFieldAsList(metadataMap, fp, BookMetadata::getCategories);
|
||||
List<String> result = service.resolveFieldAsList(metadataMap, fp, BookMetadata::getCategories);
|
||||
assertThat(result).containsExactly("Cat");
|
||||
}
|
||||
|
||||
@@ -1048,7 +1048,7 @@ class MetadataRefreshServiceTest {
|
||||
.subtitle("Sub")
|
||||
.description("Desc")
|
||||
.publisher("Pub")
|
||||
.authors(Set.of("Auth"))
|
||||
.authors(List.of("Auth"))
|
||||
.publishedDate(java.time.LocalDate.of(2020, 1, 1))
|
||||
.seriesName("Series")
|
||||
.seriesNumber(1.0f)
|
||||
@@ -1092,7 +1092,7 @@ class MetadataRefreshServiceTest {
|
||||
metadataMap.put(MetadataProvider.Amazon, BookMetadata.builder()
|
||||
.subtitle("Amazon Sub")
|
||||
.description("Amazon Desc")
|
||||
.authors(Set.of("Author A"))
|
||||
.authors(List.of("Author A"))
|
||||
.publisher("Amazon Pub")
|
||||
.publishedDate(java.time.LocalDate.of(2021, 6, 15))
|
||||
.seriesName("Amazon Series")
|
||||
|
||||
+3
-1
@@ -23,8 +23,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
@@ -93,7 +95,7 @@ class CbxMetadataWriterTest {
|
||||
meta.setPageCount(42);
|
||||
meta.setLanguage("en");
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>();
|
||||
List<AuthorEntity> authors = new ArrayList<>();
|
||||
AuthorEntity aliceAuthor = new AuthorEntity();
|
||||
aliceAuthor.setId(1L);
|
||||
aliceAuthor.setName("Alice");
|
||||
|
||||
+3
-2
@@ -28,6 +28,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@@ -70,7 +71,7 @@ class EpubMetadataWriterTest {
|
||||
metadata.setTitle("Test Book");
|
||||
AuthorEntity author = new AuthorEntity();
|
||||
author.setName("Test Author");
|
||||
metadata.setAuthors(Collections.singleton(author));
|
||||
metadata.setAuthors(List.of(author));
|
||||
|
||||
bookEntity = new BookEntity();
|
||||
LibraryPathEntity libraryPath = new LibraryPathEntity();
|
||||
@@ -174,7 +175,7 @@ class EpubMetadataWriterTest {
|
||||
newMeta.setTitle("Updated Title");
|
||||
AuthorEntity author = new AuthorEntity();
|
||||
author.setName("Updated Author");
|
||||
newMeta.setAuthors(Collections.singleton(author));
|
||||
newMeta.setAuthors(List.of(author));
|
||||
|
||||
writer.saveMetadataToFile(epubFile, newMeta, null, new MetadataClearFlags());
|
||||
String contentAfterFirstSave = readOpfContent(epubFile);
|
||||
|
||||
+3
-1
@@ -25,8 +25,10 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -87,7 +89,7 @@ class PdfMetadataWriterTest {
|
||||
meta.setLanguage("en");
|
||||
meta.setPageCount(754);
|
||||
|
||||
Set<AuthorEntity> authors = new HashSet<>();
|
||||
List<AuthorEntity> authors = new ArrayList<>();
|
||||
AuthorEntity author = new AuthorEntity();
|
||||
author.setName("Jason C McDonald");
|
||||
authors.add(author);
|
||||
|
||||
@@ -143,7 +143,7 @@ class OpdsFeedServiceTest {
|
||||
.addedOn(FIXED_INSTANT)
|
||||
.metadata(BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author A"))
|
||||
.authors(List.of("Author A"))
|
||||
.publisher("Publisher X")
|
||||
.language("en")
|
||||
.categories(Set.of("Fiction"))
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
class FileUploadServiceTest {
|
||||
|
||||
public static final Set<String> LONG_AUTHOR_LIST = new LinkedHashSet<>(List.of(
|
||||
public static final List<String> LONG_AUTHOR_LIST = new ArrayList<>(List.of(
|
||||
"梁思成", "叶嘉莹", "厉以宁", "萧乾", "冯友兰", "费孝通", "李济", "侯仁之", "汤一介", "温源宁",
|
||||
"胡适", "吴青", "李照国", "蒋梦麟", "汪荣祖", "邢玉瑞", "《中华思想文化术语》编委会",
|
||||
"北京大学政策法规研究室", "(美)艾恺(Guy S. Alitto)", "顾毓琇", "陈从周",
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -21,7 +21,7 @@ class BookUtilsTest {
|
||||
metadata.setTitle("Harry Potter");
|
||||
metadata.setSubtitle("Philosopher's Stone");
|
||||
metadata.setSeriesName("Harry Potter Series");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("J.K. Rowling").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("J.K. Rowling").build()));
|
||||
|
||||
String searchText = BookUtils.buildSearchText(metadata);
|
||||
|
||||
@@ -228,7 +228,7 @@ class BookUtilsTest {
|
||||
metadata.setTitle("The Snowman");
|
||||
metadata.setSubtitle("A Harry Hole Novel");
|
||||
metadata.setSeriesName("Harry Hole");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("Jo Nesbø").build()));
|
||||
|
||||
String searchText = BookUtils.buildSearchText(metadata);
|
||||
|
||||
@@ -245,7 +245,7 @@ class BookUtilsTest {
|
||||
void testSearchMatchingWithAndWithoutDiacritics() {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("Misère");
|
||||
metadata.setAuthors(Set.of(AuthorEntity.builder().name("François Müller").build()));
|
||||
metadata.setAuthors(List.of(AuthorEntity.builder().name("François Müller").build()));
|
||||
|
||||
String storedSearchText = BookUtils.buildSearchText(metadata);
|
||||
|
||||
@@ -311,7 +311,7 @@ class BookUtilsTest {
|
||||
void testBuildSearchText_withAuthorHavingNullName() {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("Test Book");
|
||||
Set<AuthorEntity> authors = new HashSet<>();
|
||||
List<AuthorEntity> authors = new ArrayList<>();
|
||||
authors.add(AuthorEntity.builder().name("Valid Author").build());
|
||||
authors.add(AuthorEntity.builder().name(null).build()); // Author with null name
|
||||
metadata.setAuthors(authors);
|
||||
@@ -327,7 +327,7 @@ class BookUtilsTest {
|
||||
void testBuildSearchText_withEmptyAuthorsSet() {
|
||||
BookMetadataEntity metadata = new BookMetadataEntity();
|
||||
metadata.setTitle("Test Book");
|
||||
metadata.setAuthors(new HashSet<>()); // Empty set
|
||||
metadata.setAuthors(new ArrayList<>()); // Empty list
|
||||
|
||||
String searchText = BookUtils.buildSearchText(metadata);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
@@ -84,7 +85,7 @@ public class MetadataChangeDetectorTest {
|
||||
.moodsLocked(false)
|
||||
.tagsLocked(false)
|
||||
.reviewsLocked(false)
|
||||
.authors(Set.of(
|
||||
.authors(List.of(
|
||||
AuthorEntity.builder().id(1L).name("Author One").build(),
|
||||
AuthorEntity.builder().id(2L).name("Author Two").build()
|
||||
))
|
||||
@@ -157,7 +158,7 @@ public class MetadataChangeDetectorTest {
|
||||
.moodsLocked(false)
|
||||
.tagsLocked(false)
|
||||
.reviewsLocked(false)
|
||||
.authors(Set.of("Author One", "Author Two"))
|
||||
.authors(List.of("Author One", "Author Two"))
|
||||
.categories(Set.of("Fiction", "Mystery"))
|
||||
.moods(Set.of("Dark", "Suspenseful"))
|
||||
.tags(Set.of("Thriller", "Bestseller"))
|
||||
@@ -332,7 +333,7 @@ public class MetadataChangeDetectorTest {
|
||||
.title("Original Title")
|
||||
.subtitle("Original Subtitle")
|
||||
.publisher("Original Publisher")
|
||||
.authors(Set.of()) // empty set, this is what we're testing
|
||||
.authors(List.of()) // empty set, this is what we're testing
|
||||
.authorsLocked(false)
|
||||
.categories(Set.of("Fiction"))
|
||||
.categoriesLocked(false)
|
||||
@@ -362,7 +363,7 @@ public class MetadataChangeDetectorTest {
|
||||
BookMetadataEntity testExisting = BookMetadataEntity.builder()
|
||||
.bookId(1L)
|
||||
.title("Test Title")
|
||||
.authors(Set.of()) // empty set, what we're testing
|
||||
.authors(List.of()) // empty set, what we're testing
|
||||
.authorsLocked(false)
|
||||
.categories(Set.of(CategoryEntity.builder().id(1L).name("Fiction").build()))
|
||||
.categoriesLocked(false)
|
||||
@@ -506,13 +507,11 @@ public class MetadataChangeDetectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAuthorsSetComparison_isOrderInsensitive() {
|
||||
// Change order of authors in newMeta
|
||||
newMeta.setAuthors(Set.of("Author Two", "Author One"));
|
||||
// existingMeta has Set.of("Author One", "Author Two") from setup
|
||||
void testAuthorsComparison_isOrderSensitive() {
|
||||
newMeta.setAuthors(List.of("Author Two", "Author One"));
|
||||
|
||||
boolean result = MetadataChangeDetector.isDifferent(newMeta, existingMeta, clearFlags);
|
||||
assertFalse(result, "Authors set comparison should be order insensitive");
|
||||
assertTrue(result, "Authors comparison should be order sensitive");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -562,7 +561,7 @@ public class MetadataChangeDetectorTest {
|
||||
|
||||
@Test
|
||||
void testHasValueChangesForFileWrite_includesAuthors() {
|
||||
newMeta.setAuthors(Set.of("New Author"));
|
||||
newMeta.setAuthors(List.of("New Author"));
|
||||
boolean result = MetadataChangeDetector.hasValueChangesForFileWrite(newMeta, existingMeta, clearFlags);
|
||||
assertTrue(result, "Authors change should trigger file write");
|
||||
}
|
||||
@@ -603,15 +602,15 @@ public class MetadataChangeDetectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsDifferent_whenAuthorsSetOrderChanges_returnsFalse() {
|
||||
newMeta.setAuthors(Set.of("Author Two", "Author One"));
|
||||
void testIsDifferent_whenAuthorsOrderChanges_returnsTrue() {
|
||||
newMeta.setAuthors(List.of("Author Two", "Author One"));
|
||||
boolean result = MetadataChangeDetector.isDifferent(newMeta, existingMeta, clearFlags);
|
||||
assertFalse(result, "Should return false when only author order changes");
|
||||
assertTrue(result, "Should return true when author order changes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsDifferent_whenAuthorsSetContentChanges_returnsTrue() {
|
||||
newMeta.setAuthors(Set.of("Author One", "Author Three")); // Different author
|
||||
newMeta.setAuthors(List.of("Author One", "Author Three")); // Different author
|
||||
boolean result = MetadataChangeDetector.isDifferent(newMeta, existingMeta, clearFlags);
|
||||
assertTrue(result, "Should return true when author set content changes");
|
||||
}
|
||||
@@ -638,15 +637,15 @@ public class MetadataChangeDetectorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasValueChanges_whenAuthorsSetOrderChanges_returnsFalse() {
|
||||
newMeta.setAuthors(Set.of("Author Two", "Author One"));
|
||||
void testHasValueChanges_whenAuthorsOrderChanges_returnsTrue() {
|
||||
newMeta.setAuthors(List.of("Author Two", "Author One"));
|
||||
boolean result = MetadataChangeDetector.hasValueChanges(newMeta, existingMeta, clearFlags);
|
||||
assertFalse(result, "Should return false when only author order changes");
|
||||
assertTrue(result, "Should return true when author order changes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHasValueChanges_whenMultipleCollectionsChange_returnsTrue() {
|
||||
newMeta.setAuthors(Set.of("New Author"));
|
||||
newMeta.setAuthors(List.of("New Author"));
|
||||
newMeta.setCategories(Set.of("New Category"));
|
||||
boolean result = MetadataChangeDetector.hasValueChanges(newMeta, existingMeta, clearFlags);
|
||||
assertTrue(result, "Should return true when multiple collections change");
|
||||
@@ -673,7 +672,7 @@ public class MetadataChangeDetectorTest {
|
||||
BookMetadataEntity testExisting = BookMetadataEntity.builder()
|
||||
.bookId(1L)
|
||||
.title("Test")
|
||||
.authors(Set.of())
|
||||
.authors(List.of())
|
||||
.authorsLocked(false)
|
||||
.categories(Set.of())
|
||||
.categoriesLocked(false)
|
||||
|
||||
@@ -10,9 +10,8 @@ import org.junit.jupiter.api.Test;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@@ -23,7 +22,7 @@ class PathPatternResolverTest {
|
||||
private static final int MAX_FILENAME_BYTES = 245; // From PathPatternResolver.MAX_FILESYSTEM_COMPONENT_BYTES
|
||||
private static final Charset FILENAME_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
public static final Set<String> LONG_AUTHOR_LIST = new LinkedHashSet<>(List.of(
|
||||
public static final List<String> LONG_AUTHOR_LIST = new ArrayList<>(List.of(
|
||||
"梁思成", "叶嘉莹", "厉以宁", "萧乾", "冯友兰", "费孝通", "李济", "侯仁之", "汤一介", "温源宁",
|
||||
"胡适", "吴青", "李照国", "蒋梦麟", "汪荣祖", "邢玉瑞", "《中华思想文化术语》编委会",
|
||||
"北京大学政策法规研究室", "(美)艾恺(Guy S. Alitto)", "顾毓琇", "陈从周",
|
||||
@@ -89,7 +88,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_multiplePlaceholders() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test Book")
|
||||
.authors(Set.of("John Doe", "Jane Smith"))
|
||||
.authors(List.of("John Doe", "Jane Smith"))
|
||||
.publishedDate(LocalDate.of(2023, 5, 15))
|
||||
.build();
|
||||
|
||||
@@ -103,7 +102,7 @@ class PathPatternResolverTest {
|
||||
@Test
|
||||
void testResolvePattern_authorsList() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.authors(Set.of("Author One", "Author Two"))
|
||||
.authors(List.of("Author One", "Author Two"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}", "original.pdf");
|
||||
@@ -142,7 +141,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_optionalBlock_allPresent() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author Name"))
|
||||
.authors(List.of("Author Name"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{title}< - {authors}>", "original.pdf");
|
||||
@@ -261,7 +260,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_emptyAuthors() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of())
|
||||
.authors(List.of())
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{title}< - {authors}>", "original.pdf");
|
||||
@@ -330,7 +329,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_complexPattern() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("The Great Book")
|
||||
.authors(Set.of("John Doe", "Jane Smith"))
|
||||
.authors(List.of("John Doe", "Jane Smith"))
|
||||
.seriesName("Awesome Series")
|
||||
.seriesNumber(3.0f)
|
||||
.publishedDate(LocalDate.of(2023, 5, 15))
|
||||
@@ -374,7 +373,7 @@ class PathPatternResolverTest {
|
||||
|
||||
@Test
|
||||
void testResolvePattern_authorsWithinLimit() {
|
||||
Set<String> authors = Set.of("John Doe", "Jane Smith", "Bob Wilson");
|
||||
List<String> authors = List.of("John Doe", "Jane Smith", "Bob Wilson");
|
||||
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test Book")
|
||||
@@ -390,7 +389,7 @@ class PathPatternResolverTest {
|
||||
@Test
|
||||
@DisplayName("Should apply author truncation in various pattern contexts")
|
||||
void testResolvePattern_appliesAuthorTruncation() {
|
||||
Set<String> shortAuthorList = new LinkedHashSet<>(List.of("John Doe", "Jane Smith"));
|
||||
List<String> shortAuthorList = new ArrayList<>(List.of("John Doe", "Jane Smith"));
|
||||
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test")
|
||||
@@ -429,7 +428,7 @@ class PathPatternResolverTest {
|
||||
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test")
|
||||
.authors(Set.of(veryLongAuthor))
|
||||
.authors(List.of(veryLongAuthor))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}", "test.epub");
|
||||
@@ -503,7 +502,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_removesTrailingDots() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author Name Jr."))
|
||||
.authors(List.of("Author Name Jr."))
|
||||
.build();
|
||||
|
||||
// Pattern: {authors}/{title}
|
||||
@@ -527,7 +526,7 @@ class PathPatternResolverTest {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title.")
|
||||
.seriesName("Series.")
|
||||
.authors(Set.of("Author."))
|
||||
.authors(List.of("Author."))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}/{series}/{title}", "original.pdf");
|
||||
@@ -572,7 +571,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_extensionNotInPattern() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author Name"))
|
||||
.authors(List.of("Author Name"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors} - {title}", "original.pdf");
|
||||
@@ -683,7 +682,7 @@ class PathPatternResolverTest {
|
||||
String veryLongAuthor = "A".repeat(300); // Very long single author
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test")
|
||||
.authors(Set.of(veryLongAuthor))
|
||||
.authors(List.of(veryLongAuthor))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}", "test.epub");
|
||||
@@ -701,7 +700,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_multipleTrailingDots() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title...")
|
||||
.authors(Set.of("Author Name..."))
|
||||
.authors(List.of("Author Name..."))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}/{title}", "test.pdf");
|
||||
@@ -742,7 +741,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_optionalBlockAllPresent() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Title")
|
||||
.authors(Set.of("Author"))
|
||||
.authors(List.of("Author"))
|
||||
.seriesName("Series")
|
||||
.build();
|
||||
|
||||
@@ -815,7 +814,7 @@ class PathPatternResolverTest {
|
||||
String veryLongFirstAuthor = "某".repeat(100); // ~300 bytes
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Test")
|
||||
.authors(Set.of(veryLongFirstAuthor, "Second Author"))
|
||||
.authors(List.of(veryLongFirstAuthor, "Second Author"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors}", "test.epub");
|
||||
@@ -922,7 +921,7 @@ class PathPatternResolverTest {
|
||||
void testElseClause_fallbackWithPlaceholders() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("John Doe"))
|
||||
.authors(List.of("John Doe"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "<{series}/{seriesIndex} - {title}|{title}>", "original.pdf");
|
||||
@@ -959,7 +958,7 @@ class PathPatternResolverTest {
|
||||
void testElseClause_mixedBlocks() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author"))
|
||||
.authors(List.of("Author"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "<{series}|Standalone>/<{year} - >{title}", "original.pdf");
|
||||
@@ -974,7 +973,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_firstMultipleAuthors() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(new LinkedHashSet<>(List.of("Patrick Rothfuss", "Brandon Sanderson")))
|
||||
.authors(new ArrayList<>(List.of("Patrick Rothfuss", "Brandon Sanderson")))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:first}/{title}", "original.pdf");
|
||||
@@ -987,7 +986,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_firstSingleAuthor() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:first}/{title}", "original.pdf");
|
||||
@@ -1000,7 +999,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_sort() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:sort}/{title}", "original.pdf");
|
||||
@@ -1013,7 +1012,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_sortSingleWord() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Plato"))
|
||||
.authors(List.of("Plato"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:sort}/{title}", "original.pdf");
|
||||
@@ -1038,7 +1037,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_initialAuthors() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:initial}/{authors:sort}/{title}", "original.pdf");
|
||||
@@ -1087,7 +1086,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_insideElseClause() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "<{series}|{authors:sort}>/{title}", "original.pdf");
|
||||
@@ -1100,7 +1099,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_inOptionalBlock() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "<{authors:sort}/>{title}", "original.pdf");
|
||||
@@ -1115,7 +1114,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_sortThreeWordName() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Mary Jane Watson"))
|
||||
.authors(List.of("Mary Jane Watson"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:sort}/{title}", "original.pdf");
|
||||
@@ -1128,7 +1127,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_initialSingleWordAuthor() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Plato"))
|
||||
.authors(List.of("Plato"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:initial}/{title}", "original.pdf");
|
||||
@@ -1168,7 +1167,7 @@ class PathPatternResolverTest {
|
||||
void testElseClause_multipleBlocks() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author"))
|
||||
.authors(List.of("Author"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata,
|
||||
@@ -1210,7 +1209,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_inPrimarySideOfElseClause() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.seriesName("My Series")
|
||||
.build();
|
||||
|
||||
@@ -1225,7 +1224,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_chainedDifferentFields() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Patrick Rothfuss"))
|
||||
.authors(List.of("Patrick Rothfuss"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata,
|
||||
@@ -1252,7 +1251,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_firstWithManyAuthors() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(new LinkedHashSet<>(List.of("Alice", "Bob", "Carol", "Dave")))
|
||||
.authors(new ArrayList<>(List.of("Alice", "Bob", "Carol", "Dave")))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata, "{authors:first}/{title}", "original.pdf");
|
||||
@@ -1265,7 +1264,7 @@ class PathPatternResolverTest {
|
||||
void testModifier_withElseClauseAndExtension() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("My Book")
|
||||
.authors(Set.of("Jane Doe"))
|
||||
.authors(List.of("Jane Doe"))
|
||||
.build();
|
||||
|
||||
String result = PathPatternResolver.resolvePattern(metadata,
|
||||
@@ -1306,7 +1305,7 @@ class PathPatternResolverTest {
|
||||
void testElseClause_existingPatternsUnchanged() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of("Author"))
|
||||
.authors(List.of("Author"))
|
||||
.seriesName("Series")
|
||||
.seriesNumber(1f)
|
||||
.publishedDate(LocalDate.of(2023, 1, 1))
|
||||
@@ -1323,7 +1322,7 @@ class PathPatternResolverTest {
|
||||
void testResolvePattern_removesLeadingSlash_whenFirstComponentIsEmpty() {
|
||||
BookMetadata metadata = BookMetadata.builder()
|
||||
.title("Book Title")
|
||||
.authors(Set.of()) // Empty authors
|
||||
.authors(List.of()) // Empty authors
|
||||
.build();
|
||||
|
||||
// Pattern implies a subdirectory, but authors is missing
|
||||
|
||||
Reference in New Issue
Block a user