JAVA-8638: addressing PR review comments.
This commit is contained in:
parent
686857c251
commit
fdeab133a5
@ -123,39 +123,24 @@ public class EnversFooBarAuditIntegrationTest {
|
||||
assertNotNull(barRevisionList);
|
||||
assertEquals(4, barRevisionList.size());
|
||||
|
||||
assertEquals("BAR", barRevisionList.get(0)
|
||||
.getName());
|
||||
assertEquals("BAR", barRevisionList.get(1)
|
||||
.getName());
|
||||
assertEquals("BAR1", barRevisionList.get(2)
|
||||
.getName());
|
||||
assertEquals("BAR1", barRevisionList.get(3)
|
||||
.getName());
|
||||
assertEquals("BAR", barRevisionList.get(0).getName());
|
||||
assertEquals("BAR", barRevisionList.get(1).getName());
|
||||
assertEquals("BAR1", barRevisionList.get(2).getName());
|
||||
assertEquals("BAR1", barRevisionList.get(3).getName());
|
||||
|
||||
assertEquals(1, barRevisionList.get(0)
|
||||
.getFooSet()
|
||||
.size());
|
||||
assertEquals(2, barRevisionList.get(1)
|
||||
.getFooSet()
|
||||
.size());
|
||||
assertEquals(2, barRevisionList.get(2)
|
||||
.getFooSet()
|
||||
.size());
|
||||
assertEquals(3, barRevisionList.get(3)
|
||||
.getFooSet()
|
||||
.size());
|
||||
assertEquals(1, barRevisionList.get(0).getFooSet().size());
|
||||
assertEquals(2, barRevisionList.get(1).getFooSet().size());
|
||||
assertEquals(2, barRevisionList.get(2).getFooSet().size());
|
||||
assertEquals(3, barRevisionList.get(3).getFooSet().size());
|
||||
|
||||
// test Foo revisions
|
||||
|
||||
fooRevisionList = fooService.getRevisions();
|
||||
assertNotNull(fooRevisionList);
|
||||
assertEquals(3, fooRevisionList.size());
|
||||
assertEquals("FOO1", fooRevisionList.get(0)
|
||||
.getName());
|
||||
assertEquals("FOO2", fooRevisionList.get(1)
|
||||
.getName());
|
||||
assertEquals("FOO3", fooRevisionList.get(2)
|
||||
.getName());
|
||||
assertEquals("FOO1", fooRevisionList.get(0).getName());
|
||||
assertEquals("FOO2", fooRevisionList.get(1).getName());
|
||||
assertEquals("FOO3", fooRevisionList.get(2).getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,10 +46,8 @@ public class FooFixtures {
|
||||
}
|
||||
foo2.setBar(bar);
|
||||
session.save(foo2);
|
||||
bar.getFooSet()
|
||||
.add(foo);
|
||||
bar.getFooSet()
|
||||
.add(foo2);
|
||||
bar.getFooSet().add(foo);
|
||||
bar.getFooSet().add(foo2);
|
||||
session.merge(bar);
|
||||
}
|
||||
tx.commit();
|
||||
@ -80,8 +78,7 @@ public class FooFixtures {
|
||||
final Foo foo = new Foo();
|
||||
foo.setName("Foo_" + (i + 120));
|
||||
final Bar bar = new Bar("bar_" + i);
|
||||
bar.getFooSet()
|
||||
.add(foo);
|
||||
bar.getFooSet().add(foo);
|
||||
foo.setBar(bar);
|
||||
fooList.add(foo);
|
||||
|
||||
|
@ -50,8 +50,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
session.getTransaction()
|
||||
.commit();
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@ -71,8 +70,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||
final Query query = session.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
|
||||
assertNull(fooList.get(fooList.toArray().length - 1)
|
||||
.getName());
|
||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
LOGGER.debug("Name: {}, Id: {}", foo.getName(), foo.getId());
|
||||
}
|
||||
@ -83,8 +81,7 @@ public class FooSortingPersistenceIntegrationTest {
|
||||
final String hql = "FROM Foo f ORDER BY f.name NULLS FIRST";
|
||||
final Query query = session.createQuery(hql);
|
||||
final List<Foo> fooList = query.list();
|
||||
assertNull(fooList.get(0)
|
||||
.getName());
|
||||
assertNull(fooList.get(0).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
LOGGER.debug("Name: {}", foo.getName());
|
||||
|
||||
@ -145,11 +142,9 @@ public class FooSortingPersistenceIntegrationTest {
|
||||
@Test
|
||||
public final void whenCriteriaSortingStringNullsLastAsc_thenNullsLast() {
|
||||
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
||||
criteria.addOrder(Order.asc("name")
|
||||
.nulls(NullPrecedence.LAST));
|
||||
criteria.addOrder(Order.asc("name").nulls(NullPrecedence.LAST));
|
||||
final List<Foo> fooList = criteria.list();
|
||||
assertNull(fooList.get(fooList.toArray().length - 1)
|
||||
.getName());
|
||||
assertNull(fooList.get(fooList.toArray().length - 1).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||
}
|
||||
@ -158,11 +153,9 @@ public class FooSortingPersistenceIntegrationTest {
|
||||
@Test
|
||||
public final void whenCriteriaSortingStringNullsFirstDesc_thenNullsFirst() {
|
||||
final Criteria criteria = session.createCriteria(Foo.class, "FOO");
|
||||
criteria.addOrder(Order.desc("name")
|
||||
.nulls(NullPrecedence.FIRST));
|
||||
criteria.addOrder(Order.desc("name").nulls(NullPrecedence.FIRST));
|
||||
final List<Foo> fooList = criteria.list();
|
||||
assertNull(fooList.get(0)
|
||||
.getName());
|
||||
assertNull(fooList.get(0).getName());
|
||||
for (final Foo foo : fooList) {
|
||||
LOGGER.debug("Id: {}, FirstName: {}", foo.getId(), foo.getName());
|
||||
}
|
||||
|
@ -40,42 +40,46 @@ public class UserRepositoryIntegrationTest {
|
||||
@Test
|
||||
public void whenFindAllSortedByNameThenAllSorted() {
|
||||
List<User> allUsersSortedByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name"));
|
||||
assertThat(allUsersSortedByName).extracting("name")
|
||||
assertThat(allUsersSortedByName)
|
||||
.extracting("name")
|
||||
.containsSequence("Bob", "Cindy", "John");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFindAllSortedByNameLengthThenException() {
|
||||
assertThatThrownBy(() -> userRepository.findAll(Sort.by("LENGTH(name)"))).isInstanceOf(PropertyReferenceException.class);
|
||||
assertThatThrownBy(() -> userRepository.findAll(Sort.by("LENGTH(name)")))
|
||||
.isInstanceOf(PropertyReferenceException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFindAllUsersSortedByNameThenAllSorted() {
|
||||
List<User> allUsersSortedByName = userRepository.findAllUsers(Sort.by(Sort.Direction.ASC, "name"));
|
||||
assertThat(allUsersSortedByName).extracting("name")
|
||||
assertThat(allUsersSortedByName)
|
||||
.extracting("name")
|
||||
.containsSequence("Bob", "Cindy", "John");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFindAllUsersSortedByNameLengthThenAllSorted() {
|
||||
List<User> allUsersSortedByName = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)"));
|
||||
assertThat(allUsersSortedByName).extracting("name")
|
||||
assertThat(allUsersSortedByName)
|
||||
.extracting("name")
|
||||
.containsSequence("Bob", "John", "Cindy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFindAllUsersWithPaginationThenPaginated() {
|
||||
Page<User> page = userRepository.findAllUsersWithPagination(PageRequest.of(0, 1));
|
||||
assertThat(page.stream()
|
||||
.map(User::getId)).hasSize(1)
|
||||
assertThat(page.stream().map(User::getId))
|
||||
.hasSize(1)
|
||||
.containsOnly(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFindAllUsersWithPaginationNativeThenPaginated() {
|
||||
Page<User> page = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 1));
|
||||
assertThat(page.stream()
|
||||
.map(User::getId)).hasSize(1)
|
||||
assertThat(page.stream().map(User::getId))
|
||||
.hasSize(1)
|
||||
.containsOnly(2);
|
||||
}
|
||||
|
||||
@ -122,7 +126,8 @@ public class UserRepositoryIntegrationTest {
|
||||
@Test
|
||||
public void whenFindUserByNameListThenAllFound() {
|
||||
List<User> users = userRepository.findUserByNameList(Arrays.asList("Bob", "Cindy"));
|
||||
assertThat(users).extracting("name")
|
||||
assertThat(users)
|
||||
.extracting("name")
|
||||
.containsOnly("Bob", "Cindy");
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,7 @@ public class HibernateUtil {
|
||||
configuration.addAnnotatedClass(Event.class);
|
||||
configuration.addAnnotatedClass(EventGeneratedId.class);
|
||||
configuration.configure("immutable.cfg.xml");
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
|
||||
.build();
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
|
||||
return configuration.buildSessionFactory(serviceRegistry);
|
||||
} catch (Throwable ex) {
|
||||
LOGGER.debug("Initial SessionFactory creation failed.", ex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user