[BAEL-7609] - Fixed spring-boot integration tests
This commit is contained in:
+4
-6
@@ -4,17 +4,15 @@ import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.baeldung.boot.ApplicationIntegrationTest;
|
||||
import org.baeldung.boot.DemoApplicationIntegrationTest;
|
||||
import org.baeldung.demo.model.Foo;
|
||||
import org.baeldung.session.exception.repository.FooRepository;
|
||||
import org.baeldung.demo.repository.FooRepository;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@TestPropertySource("classpath:exception-hibernate.properties")
|
||||
public class HibernateSessionIntegrationTest extends ApplicationIntegrationTest {
|
||||
public class HibernateSessionIntegrationTest extends DemoApplicationIntegrationTest {
|
||||
@Autowired
|
||||
private FooRepository fooRepository;
|
||||
|
||||
@@ -23,7 +21,7 @@ public class HibernateSessionIntegrationTest extends ApplicationIntegrationTest
|
||||
Foo foo = new Foo("Exception Solved");
|
||||
fooRepository.save(foo);
|
||||
foo = null;
|
||||
foo = fooRepository.get(1);
|
||||
foo = fooRepository.findByName("Exception Solved");
|
||||
|
||||
assertThat(foo, notNullValue());
|
||||
assertThat(foo.getId(), is(1));
|
||||
|
||||
+2
@@ -6,9 +6,11 @@ import org.baeldung.session.exception.repository.FooRepository;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
@TestPropertySource("classpath:exception-hibernate.properties")
|
||||
public class NoHibernateSessionIntegrationTest extends ApplicationIntegrationTest {
|
||||
@Autowired
|
||||
private FooRepository fooRepository;
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class CustomConverterIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void whenConvertingToBigDecimalUsingGenericConverter_thenSuccess() {
|
||||
assertThat(conversionService.convert(Integer.valueOf(11), BigDecimal.class)).isEqualTo(BigDecimal.valueOf(11.00).setScale(2, BigDecimal.ROUND_HALF_EVEN));
|
||||
assertThat(conversionService.convert(Integer.valueOf(11), BigDecimal.class)).isEqualTo(BigDecimal.valueOf(11.00).setScale(0, BigDecimal.ROUND_HALF_EVEN));
|
||||
assertThat(conversionService.convert(Double.valueOf(25.23), BigDecimal.class)).isEqualByComparingTo(BigDecimal.valueOf(Double.valueOf(25.23)));
|
||||
assertThat(conversionService.convert("2.32", BigDecimal.class)).isEqualTo(BigDecimal.valueOf(2.32));
|
||||
}
|
||||
|
||||
+8
-11
@@ -1,9 +1,11 @@
|
||||
package org.baeldung.demo.boottest;
|
||||
|
||||
import org.baeldung.demo.boottest.Employee;
|
||||
import org.baeldung.demo.boottest.EmployeeRepository;
|
||||
import org.baeldung.demo.boottest.EmployeeService;
|
||||
import org.baeldung.demo.boottest.EmployeeServiceImpl;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -15,11 +17,6 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class EmployeeServiceImplIntegrationTest {
|
||||
|
||||
@@ -50,9 +47,9 @@ public class EmployeeServiceImplIntegrationTest {
|
||||
Mockito.when(employeeRepository.findByName(john.getName())).thenReturn(john);
|
||||
Mockito.when(employeeRepository.findByName(alex.getName())).thenReturn(alex);
|
||||
Mockito.when(employeeRepository.findByName("wrong_name")).thenReturn(null);
|
||||
Mockito.when(employeeRepository.findById(john.getId()).orElse(null)).thenReturn(john);
|
||||
Mockito.when(employeeRepository.findById(john.getId())).thenReturn(Optional.of(john));
|
||||
Mockito.when(employeeRepository.findAll()).thenReturn(allEmployees);
|
||||
Mockito.when(employeeRepository.findById(-99L).orElse(null)).thenReturn(null);
|
||||
Mockito.when(employeeRepository.findById(-99L)).thenReturn(Optional.empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user