mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 14:05:50 +00:00
Added some asserts on PetclinicIntegrationTests
This commit is contained in:
parent
60105d5d9a
commit
b6df5f4dd0
3 changed files with 40 additions and 8 deletions
|
@ -17,6 +17,7 @@ package org.springframework.samples.petclinic.model;
|
|||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -45,4 +46,17 @@ public class NamedEntity extends BaseEntity {
|
|||
return this.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof NamedEntity)) return false;
|
||||
NamedEntity that = (NamedEntity) o;
|
||||
return Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,11 +15,7 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -29,6 +25,7 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.Table;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.samples.petclinic.model.Person;
|
||||
|
@ -76,4 +73,17 @@ public class Vet extends Person {
|
|||
getSpecialtiesInternal().add(specialty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Vet)) return false;
|
||||
Vet vet = (Vet) o;
|
||||
return Objects.equals(specialties, vet.specialties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(specialties);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,17 @@ package org.springframework.samples.petclinic;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.samples.petclinic.vet.Vet;
|
||||
import org.springframework.samples.petclinic.vet.VetRepository;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class PetclinicIntegrationTests {
|
||||
|
@ -33,7 +38,10 @@ public class PetclinicIntegrationTests {
|
|||
|
||||
@Test
|
||||
public void testFindAll() throws Exception {
|
||||
vets.findAll();
|
||||
vets.findAll(); // served from cache
|
||||
final Collection<Vet> firstRequest = vets.findAll();
|
||||
final Collection<Vet> secondRequest = vets.findAll(); // served from cache
|
||||
|
||||
assertThat(firstRequest.size()).isEqualTo(secondRequest.size());
|
||||
assertThat(firstRequest).isEqualTo(secondRequest);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue