diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java index d5e2af9..8c5ca6f 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java @@ -1,8 +1,10 @@ package ntnu.systemutvikling.team6.scraper.scraperComponents; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,7 +42,7 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() { when(p1.getText()).thenReturn("Short description"); when(p2.getText()).thenReturn(""); - when(scraper.findElements(By.cssSelector(".information div p"))).thenReturn(List.of(p1, p2)); + when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, p2)); when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of()); @@ -64,13 +66,13 @@ void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() { when(p1.getText()).thenReturn("Intro"); when(extra.getText()).thenReturn("Extra info"); - when(scraper.findElements(By.cssSelector(".information div p"))).thenReturn(List.of(p1)); + when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, extra)); when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(readMore)); when(scraper.findElement(By.cssSelector("a.read-more"))).thenReturn(readMore); - when(scraper.findElements(By.cssSelector(".extra-info p"))).thenReturn(List.of(extra)); + when(scraper.findElements(By.cssSelector(".extra-info"))).thenReturn(List.of(extra)); scraper.updateDescription(); @@ -102,14 +104,18 @@ void updateCategoriesShouldReturnCorrectCategories() { when(c1.getText()).thenReturn("Health"); when(c2.getText()).thenReturn("Education"); + List categories = new ArrayList<>(); + categories.add("Health"); + categories.add("Education"); + when(scraper.findElements(By.cssSelector(".tag-label"))).thenReturn(List.of(c1, c2)); scraper.updateCategories(); assertEquals( - "Health,Education", + categories, scraper.getCategories(), - "Should return a string that lists categories with ',' as a delimiter."); + "Should return an list that contain two string elements 'Health' and 'Education'."); } @Test