BAEL-3733: Fix integration tests (#8500)

This commit is contained in:
kwoyke 2020-01-09 22:21:14 +01:00 committed by Grzegorz Piwowarek
parent 8d5426f7d5
commit 31889765c3
2 changed files with 15 additions and 16 deletions

View File

@ -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"));
}
}

View File

@ -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"));
}
}