diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java index f0f02c41d3..d6edab9421 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/Country.java @@ -1,15 +1,13 @@ package com.baeldung.h2db.springboot.models; -import lombok.Data; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import java.util.Objects; @Table(name = "countries") @Entity -@Data public class Country { @Id @@ -18,4 +16,42 @@ public class Country { private String name; + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Country country = (Country) o; + return id == country.id && name.equals(country.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + @Override + public String toString() { + return "Country{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } } diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java index abdbd76c19..4c11ae6b0d 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java @@ -15,6 +15,8 @@ import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest(classes = SpringBootH2Application.class) public class SpringBootH2IntegrationTest { + private static final Country AN_EXPECTED_COUNTRY = buildCountry(); + @Autowired private CountryRepository countryRepository; @@ -22,7 +24,16 @@ public class SpringBootH2IntegrationTest { public void givenInitData_whenApplicationStarts_thenDataIsLoaded() { Iterable users = countryRepository.findAll(); - assertThat(users).hasSize(5); + assertThat(users) + .hasSize(5) + .contains(AN_EXPECTED_COUNTRY); + } + + private static Country buildCountry() { + Country c = new Country(); + c.setId(5); + c.setName("Canada"); + return c; } }