diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java index 5d02d34f53..c32e36d7e3 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java @@ -1,19 +1,17 @@ package org.baeldung.boot.repository; -import static org.junit.Assert.assertThat; - import org.baeldung.boot.DemoApplicationIntegrationTest; import org.baeldung.demo.model.Foo; import org.baeldung.demo.repository.FooRepository; - -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.is; - import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + @Transactional public class FooRepositoryIntegrationTest extends DemoApplicationIntegrationTest { @Autowired @@ -28,8 +26,10 @@ public class FooRepositoryIntegrationTest extends DemoApplicationIntegrationTest @Test public void testFindByName() { Foo foo = fooRepository.findByName("Bar"); + assertThat(foo, notNullValue()); - assertThat(foo.getId(), is(2)); + assertThat(foo.getId(), notNullValue()); + assertThat(foo.getName(), is("Bar")); } } diff --git a/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java index baa4f70e83..b22282e896 100644 --- a/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java @@ -1,9 +1,5 @@ package org.baeldung.boot.repository; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - import org.baeldung.boot.DemoApplicationIntegrationTest; import org.baeldung.demo.model.Foo; import org.baeldung.demo.repository.FooRepository; @@ -11,6 +7,10 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + @Transactional public class HibernateSessionIntegrationTest extends DemoApplicationIntegrationTest { @Autowired @@ -18,13 +18,12 @@ public class HibernateSessionIntegrationTest extends DemoApplicationIntegrationT @Test public void whenSavingWithCurrentSession_thenThrowNoException() { - Foo foo = new Foo("Exception Solved"); - fooRepository.save(foo); - foo = null; - foo = fooRepository.findByName("Exception Solved"); + fooRepository.save(new Foo("Exception Solved")); + + Foo foo = fooRepository.findByName("Exception Solved"); assertThat(foo, notNullValue()); - assertThat(foo.getId(), is(1)); + assertThat(foo.getId(), notNullValue()); assertThat(foo.getName(), is("Exception Solved")); } }