11package org .baeldung .persistence .service ;
22
3- import static org .apache . commons . lang3 . RandomStringUtils . randomAlphabetic ;
3+ import static org .junit . Assert . assertNull ;
44
5- import org .baeldung .persistence .model .Foo ;
6- import org .baeldung .persistence .service .IFooService ;
7- import org .baeldung .spring .PersistenceConfig ;
8- import org .junit .Ignore ;
9- import org .junit .Test ;
10- import org .junit .runner .RunWith ;
11- import org .springframework .beans .factory .annotation .Autowired ;
12- import org .springframework .dao .DataAccessException ;
13- import org .springframework .dao .DataIntegrityViolationException ;
14- import org .springframework .dao .InvalidDataAccessApiUsageException ;
15- import org .springframework .test .context .ContextConfiguration ;
16- import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
17- import org .springframework .test .context .support .AnnotationConfigContextLoader ;
18- import static org .junit .Assert .*;
19- import org .junit .BeforeClass ;
20- import org .junit .Test ;
21- import org .junit .After ;
225import java .util .List ;
236import java .util .Set ;
7+
8+ import org .baeldung .persistence .model .Bar ;
9+ import org .baeldung .persistence .model .Foo ;
10+ import org .baeldung .spring .PersistenceConfig ;
2411import org .hibernate .Criteria ;
2512import org .hibernate .NullPrecedence ;
2613import org .hibernate .Query ;
2916import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
3017import org .hibernate .cfg .Configuration ;
3118import org .hibernate .criterion .Order ;
32- import com .cc .example .hibernate .Foo ;
33- import com .cc .example .hibernate .Bar ;
19+ import org .junit .After ;
20+ import org .junit .BeforeClass ;
21+ import org .junit .Test ;
22+ import org .junit .runner .RunWith ;
23+ import org .springframework .test .context .ContextConfiguration ;
24+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
25+ import org .springframework .test .context .support .AnnotationConfigContextLoader ;
26+
3427
3528@ RunWith (SpringJUnit4ClassRunner .class )
3629@ ContextConfiguration (classes = { PersistenceConfig .class }, loader = AnnotationConfigContextLoader .class )
@@ -81,7 +74,6 @@ public final void whenHQlSortingByStringNullLast_thenLastNull() {
8174 System .out .println ("Name: " + foo .getName () + ", Id: " + foo .getId ());
8275 }
8376 sess .getTransaction ().commit ();
84-
8577 }
8678
8779 @ Test
@@ -96,7 +88,6 @@ public final void whenSortingByStringNullsFirst_thenReturnNullsFirst() {
9688
9789 }
9890 sess .getTransaction ().commit ();
99-
10091 }
10192
10293 @ Test
@@ -108,10 +99,9 @@ public final void whenHQlSortingByOneAttribute_andOrderDirection_thenPrintSorted
10899 for (final Foo foo : fooList ) {
109100 System .out .println ("Name: " + foo .getName () + ", Id: " + foo .getId ()
110101
111- );
102+ );
112103 }
113104 sess .getTransaction ().commit ();
114-
115105 }
116106
117107 @ Test
@@ -123,10 +113,9 @@ public final void whenHQlSortingByMultipleAttributes_thenSortedResults() {
123113 for (final Foo foo : fooList ) {
124114 System .out .println ("Name: " + foo .getName () + ", Id: " + foo .getId ()
125115
126- );
116+ );
127117 }
128118 sess .getTransaction ().commit ();
129-
130119 }
131120
132121 @ Test
@@ -139,7 +128,6 @@ public final void whenHQlSortingByMultipleAttributes_andOrderDirection_thenPrint
139128 System .out .println ("Name: " + foo .getName () + ", Id: " + foo .getId ());
140129 }
141130 sess .getTransaction ().commit ();
142-
143131 }
144132
145133 @ Test
@@ -152,7 +140,6 @@ public final void whenHQLCriteriaSortingByOneAttr_thenPrintSortedResults() {
152140 System .out .println ("Id: " + foo .getId () + ", FirstName: " + foo .getName ());
153141 }
154142 sess .getTransaction ().commit ();
155-
156143 }
157144
158145 @ Test
@@ -166,7 +153,6 @@ public final void whenHQLCriteriaSortingByMultipAttr_thenSortedResults() {
166153 System .out .println ("Id: " + foo .getId () + ", FirstName: " + foo .getName ());
167154 }
168155 sess .getTransaction ().commit ();
169-
170156 }
171157
172158 @ Test
@@ -178,10 +164,8 @@ public final void whenCriteriaSortingStringNullsLastAsc_thenNullsLast() {
178164 assertNull (fooList .get (fooList .toArray ().length - 1 ).getName ());
179165 for (final Foo foo : fooList ) {
180166 System .out .println ("Id: " + foo .getId () + ", FirstName: " + foo .getName ());
181-
182167 }
183168 sess .getTransaction ().commit ();
184-
185169 }
186170
187171 @ Test
@@ -206,7 +190,7 @@ public final void whenSortingBars_thenBarsWithSortedFoos() {
206190 final Query query = sess .createQuery (hql );
207191 final List <Bar > barList = query .list ();
208192 for (final Bar bar : barList ) {
209- final Set <Foo > fooSet = bar .getFooList ();
193+ final Set <Foo > fooSet = bar .getFooSet ();
210194 System .out .println ("Bar Id:" + bar .getId ());
211195 for (final Foo foo : fooSet ) {
212196 System .out .println ("FooName:" + foo .getName ());
0 commit comments