feat(google-parser): improve Google Books API integration with improved metadata handling and series extraction (#2375)

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs
2026-01-21 22:37:04 -07:00
committed by GitHub
parent 67c12223ea
commit 193c9495a1
3 changed files with 486 additions and 31 deletions
@@ -0,0 +1,69 @@
package com.adityachandel.booklore.service.metadata.parser;
import com.adityachandel.booklore.service.appsettings.AppSettingService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class GoogleParserTest {
@Mock
private AppSettingService appSettingService;
@Mock
private ObjectMapper objectMapper;
private GoogleParser googleParser;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
googleParser = new GoogleParser(objectMapper, appSettingService);
}
@Test
void testCleanDescription_null() {
assertNull(googleParser.cleanDescription(null));
}
@Test
void testCleanDescription_empty() {
assertNull(googleParser.cleanDescription(""));
assertNull(googleParser.cleanDescription(" "));
}
@Test
void testCleanDescription_withHtmlTags() {
String input = "This is <i>italic</i> and <b>bold</b>. <br> New line.";
String expected = "This is italic and bold. New line.";
assertEquals(expected, googleParser.cleanDescription(input));
}
@Test
void testCleanDescription_withEntities() {
String input = "Tom &amp; Jerry &lt; Disney &gt; Pixar &quot;Toy Story&quot; &#39;test&#39;";
String expected = "Tom & Jerry < Disney > Pixar \"Toy Story\" 'test'";
assertEquals(expected, googleParser.cleanDescription(input));
}
@Test
void testCleanDescription_withNestedTagsAndWhitespace() {
String input = """
<div> <p>Some text </p>
<span>More text</span> </div>""";
String expected = "Some text More text";
assertEquals(expected, googleParser.cleanDescription(input));
}
@Test
void testCleanDescription_withUnclosedTags() {
String input = "This is <i>italic and <b>bold";
String expected = "This is italic and bold";
assertEquals(expected, googleParser.cleanDescription(input));
}
}