From 1dbda278f91d75393b36c1b40dbdf741216638fb Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 9 Mar 2020 18:39:14 +0000 Subject: [PATCH] Add test --- .../metamodel/mapping/array/ArrayTests.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/array/ArrayTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/array/ArrayTests.java index 61586889e7..493f5815d5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/array/ArrayTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/array/ArrayTests.java @@ -48,6 +48,58 @@ public class ArrayTests { ); } + @Test + public void emptyArrayTest(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Employee employee = new Employee( 2, "Andrea" ); + session.save( employee ); + } + ); + + scope.inTransaction( + session -> { + final QueryImplementor query = session.createQuery( + "select e from Employee e where e.id = :id", + Employee.class + ); + final Employee result = query.setParameter( "id", 2 ).uniqueResult(); + + assertThat( result, notNullValue() ); + assertThat( result.getName(), is( "Andrea" ) ); + String[] todo = result.getToDoList(); + assertThat( todo.length, is( 0 ) ); + } + ); + + scope.inTransaction( + session -> { + final QueryImplementor query = session.createQuery( + "select e from Employee e ", + Employee.class + ); + final List results = query.list(); + + assertThat( results.size(), is( 2 ) ); + results.forEach( employee -> { + if ( employee.getId() == 1 ) { + assertThat( employee.getName(), is( "Koen" ) ); + String[] todo = employee.getToDoList(); + assertThat( todo.length, is( 3 ) ); + assertThat( todo[0], is( "metro" ) ); + assertThat( todo[1], is( "boulot" ) ); + assertThat( todo[2], is( "dodo" ) ); + } + else { + assertThat( employee.getName(), is( "Andrea" ) ); + String[] todo = employee.getToDoList(); + assertThat( todo.length, is( 0 ) ); + } + } ); + } + ); + } + @BeforeEach public void setUp(SessionFactoryScope scope) { scope.inTransaction(