This commit is contained in:
Ekaterina Galkina
2019-04-10 18:47:23 +05:00
parent 34c0cbe8e3
commit 0554797999
3 changed files with 6 additions and 7 deletions
@@ -1,66 +0,0 @@
package com.baeldung.customer;
import com.baeldung.config.PersistenceConfiguration;
import com.baeldung.config.PersistenceProductConfiguration;
import com.baeldung.config.PersistenceUserConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
import static org.junit.Assert.assertEquals;
@DataJpaTest(excludeAutoConfiguration = { PersistenceConfiguration.class, PersistenceUserConfiguration.class, PersistenceProductConfiguration.class })
@RunWith(SpringRunner.class)
public class CustomerRepositoryIntegrationTest {
@PersistenceContext
private EntityManager entityManager;
@Autowired
private CustomerRepository repository;
@Before
public void before() {
entityManager.persist(new Customer("A", "A@example.com"));
entityManager.persist(new Customer("D", null));
entityManager.persist(new Customer("D", "D@example.com"));
}
@Test
public void givenQueryMethod_whenEmailIsNull_thenFoundByNullEmail() {
List<Customer> customers = repository.findByNameAndEmail("D", null);
assertEquals(1, customers.size());
Customer actual = customers.get(0);
assertEquals(null, actual.getEmail());
assertEquals("D", actual.getName());
}
@Test
public void givenQueryMethod_whenEmailIsAbsent_thenIgnoreEmail() {
List<Customer> customers = repository.findByName("D");
assertEquals(2, customers.size());
}
@Test
public void givenQueryAnnotation_whenEmailIsNull_thenIgnoreEmail() {
List<Customer> customers = repository.findCustomerByNameAndEmail("D", null);
assertEquals(2, customers.size());
}
@After
public void cleanUp() {
repository.deleteAll();
}
}