From 8f799263e00b9fcf0d8ca78d864d8b46ce3b8aea Mon Sep 17 00:00:00 2001 From: Anyul Rivas Date: Tue, 19 Mar 2024 09:32:15 +0100 Subject: [PATCH] test: remove duplicate assertion --- .../petclinic/owner/OwnerControllerTests.java | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java index 60950a61233..618ee5b20b3 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java @@ -17,8 +17,6 @@ package org.springframework.samples.petclinic.owner; import org.assertj.core.util.Lists; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledInNativeImage; @@ -33,7 +31,6 @@ import org.springframework.test.web.servlet.MockMvc; import java.time.LocalDate; -import java.util.List; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; @@ -94,9 +91,9 @@ void setup() { Owner george = george(); given(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))) - .willReturn(new PageImpl(Lists.newArrayList(george))); + .willReturn(new PageImpl<>(Lists.newArrayList(george))); - given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl(Lists.newArrayList(george))); + given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<>(Lists.newArrayList(george))); given(this.owners.findById(TEST_OWNER_ID)).willReturn(george); Visit visit = new Visit(); @@ -145,14 +142,14 @@ void testInitFindForm() throws Exception { @Test void testProcessFindFormSuccess() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList(george(), new Owner())); + Page tasks = new PageImpl<>(Lists.newArrayList(george(), new Owner())); Mockito.when(this.owners.findByLastName(anyString(), any(Pageable.class))).thenReturn(tasks); mockMvc.perform(get("/owners?page=1")).andExpect(status().isOk()).andExpect(view().name("owners/ownersList")); } @Test void testProcessFindFormByLastName() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList(george())); + Page tasks = new PageImpl<>(Lists.newArrayList(george())); Mockito.when(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))).thenReturn(tasks); mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin")) .andExpect(status().is3xxRedirection()) @@ -161,7 +158,7 @@ void testProcessFindFormByLastName() throws Exception { @Test void testProcessFindFormNoOwnersFound() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList()); + Page tasks = new PageImpl<>(Lists.newArrayList()); Mockito.when(this.owners.findByLastName(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks); mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname")) .andExpect(status().isOk()) @@ -228,21 +225,6 @@ void testShowOwner() throws Exception { .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) .andExpect(model().attribute("owner", hasProperty("pets", not(empty())))) .andExpect(model().attribute("owner", hasProperty("pets", hasItem(hasProperty("visits", hasSize(greaterThan(0))))))) - .andExpect(model().attribute("owner", hasProperty("pets", new BaseMatcher>() { - - @Override - public boolean matches(Object item) { - @SuppressWarnings("unchecked") - List pets = (List) item; - Pet pet = pets.get(0); - return !pet.getVisits().isEmpty(); - } - - @Override - public void describeTo(Description description) { - description.appendText("Max did not have any visits"); - } - }))) .andExpect(view().name("owners/ownerDetails")); }