11package org .baeldung .dao ;
22
3- import junit .framework .Assert ;
3+ import java .util .Map ;
4+
45import org .baeldung .entity .Person ;
56import org .junit .Test ;
67import org .junit .runner .RunWith ;
1011import org .springframework .test .context .transaction .TransactionConfiguration ;
1112import org .springframework .transaction .annotation .Transactional ;
1213
13- import java .util .Map ;
14-
14+ import junit .framework .Assert ;
1515
1616@ ContextConfiguration ("/test-context.xml" )
1717@ RunWith (SpringJUnit4ClassRunner .class )
1818@ Transactional
19- @ TransactionConfiguration (defaultRollback = true )
19+ @ TransactionConfiguration (defaultRollback = true )
2020public class PersonDaoTest {
2121
2222 @ Autowired
2323 private PersonDao personDao ;
2424
25+ //
26+
2527 @ Test
2628 public void testCreation () {
2729 personDao .save (new Person ("Erich" , "Gamma" ));
28- Person person = new Person ("Kent" , "Beck" );
30+ final Person person = new Person ("Kent" , "Beck" );
2931 personDao .save (person );
3032 personDao .save (new Person ("Ralph" , "Johnson" ));
3133
32- Person personFromDb = personDao .findPersonsByFirstnameQueryDSL ("Kent" ).get (0 );
34+ final Person personFromDb = personDao .findPersonsByFirstnameQueryDSL ("Kent" ).get (0 );
3335 Assert .assertEquals (person .getId (), personFromDb .getId ());
3436 }
3537
3638 @ Test
3739 public void testMultipleFilter () {
3840 personDao .save (new Person ("Erich" , "Gamma" ));
39- Person person = personDao .save (new Person ("Ralph" , "Beck" ));
40- Person person2 = personDao .save (new Person ("Ralph" , "Johnson" ));
41+ final Person person = personDao .save (new Person ("Ralph" , "Beck" ));
42+ final Person person2 = personDao .save (new Person ("Ralph" , "Johnson" ));
4143
42- Person personFromDb = personDao .findPersonsByFirstnameAndSurnameQueryDSL ("Ralph" , "Johnson" ).get (0 );
44+ final Person personFromDb = personDao .findPersonsByFirstnameAndSurnameQueryDSL ("Ralph" , "Johnson" ).get (0 );
4345 Assert .assertNotSame (person .getId (), personFromDb .getId ());
4446 Assert .assertEquals (person2 .getId (), personFromDb .getId ());
4547 }
4648
4749 @ Test
4850 public void testOrdering () {
49- Person person = personDao .save (new Person ("Kent" , "Gamma" ));
51+ final Person person = personDao .save (new Person ("Kent" , "Gamma" ));
5052 personDao .save (new Person ("Ralph" , "Johnson" ));
51- Person person2 = personDao .save (new Person ("Kent" , "Zivago" ));
53+ final Person person2 = personDao .save (new Person ("Kent" , "Zivago" ));
5254
53- Person personFromDb = personDao .findPersonsByFirstnameInDescendingOrderQueryDSL ("Kent" ).get (0 );
55+ final Person personFromDb = personDao .findPersonsByFirstnameInDescendingOrderQueryDSL ("Kent" ).get (0 );
5456 Assert .assertNotSame (person .getId (), personFromDb .getId ());
5557 Assert .assertEquals (person2 .getId (), personFromDb .getId ());
5658 }
@@ -61,7 +63,7 @@ public void testMaxAge() {
6163 personDao .save (new Person ("Ralph" , "Johnson" , 35 ));
6264 personDao .save (new Person ("Kent" , "Zivago" , 30 ));
6365
64- int maxAge = personDao .findMaxAge ();
66+ final int maxAge = personDao .findMaxAge ();
6567 Assert .assertTrue (maxAge == 35 );
6668 }
6769
@@ -71,7 +73,7 @@ public void testMaxAgeByName() {
7173 personDao .save (new Person ("Ralph" , "Johnson" , 35 ));
7274 personDao .save (new Person ("Kent" , "Zivago" , 30 ));
7375
74- Map <String , Integer > maxAge = personDao .findMaxAgeByName ();
76+ final Map <String , Integer > maxAge = personDao .findMaxAgeByName ();
7577 Assert .assertTrue (maxAge .size () == 2 );
7678 Assert .assertSame (35 , maxAge .get ("Ralph" ));
7779 Assert .assertSame (30 , maxAge .get ("Kent" ));
0 commit comments