Skip to content

Commit

Permalink
test: remove duplicate assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
anyulled authored and dsyer committed May 16, 2024
1 parent 19f5268 commit 8f79926
Showing 1 changed file with 5 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -94,9 +91,9 @@ void setup() {

Owner george = george();
given(this.owners.findByLastName(eq("Franklin"), any(Pageable.class)))
.willReturn(new PageImpl<Owner>(Lists.newArrayList(george)));
.willReturn(new PageImpl<>(Lists.newArrayList(george)));

given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<Owner>(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();
Expand Down Expand Up @@ -145,14 +142,14 @@ void testInitFindForm() throws Exception {

@Test
void testProcessFindFormSuccess() throws Exception {
Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList(george(), new Owner()));
Page<Owner> 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<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList(george()));
Page<Owner> 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())
Expand All @@ -161,7 +158,7 @@ void testProcessFindFormByLastName() throws Exception {

@Test
void testProcessFindFormNoOwnersFound() throws Exception {
Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList());
Page<Owner> 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())
Expand Down Expand Up @@ -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<List<Pet>>() {

@Override
public boolean matches(Object item) {
@SuppressWarnings("unchecked")
List<Pet> pets = (List<Pet>) 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"));
}

Expand Down

0 comments on commit 8f79926

Please sign in to comment.