@@ -478,6 +478,7 @@ public interface ErrorMapper {
478
478
void multipleProviderContext ();
479
479
}
480
480
481
+ @ SuppressWarnings ("unused" )
481
482
public static class ErrorSqlBuilder {
482
483
public void methodNotFound () {
483
484
throw new UnsupportedOperationException ("methodNotFound" );
@@ -516,6 +517,7 @@ public interface StaticMethodSqlProviderMapper {
516
517
@ SelectProvider (type = SqlProvider .class , method = "oneArgumentAndProviderContext" )
517
518
String oneArgumentAndProviderContext (Integer value );
518
519
520
+ @ SuppressWarnings ("unused" )
519
521
class SqlProvider {
520
522
521
523
public static String noArgument () {
@@ -547,27 +549,22 @@ public static String oneArgumentAndProviderContext(Integer value, ProviderContex
547
549
}
548
550
549
551
@ Test
550
- public void shouldInsertUserSelective () {
551
- SqlSession sqlSession = sqlSessionFactory .openSession ();
552
- try {
552
+ void shouldInsertUserSelective () {
553
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
553
554
Mapper mapper = sqlSession .getMapper (Mapper .class );
554
555
User user = new User ();
555
556
user .setId (999 );
556
557
mapper .insertSelective (user );
557
558
558
559
User loadedUser = mapper .getUser (999 );
559
- assertEquals (null , loadedUser .getName ());
560
-
561
- } finally {
562
- sqlSession .close ();
560
+ assertNull (loadedUser .getName ());
563
561
}
564
562
}
565
563
566
564
567
565
@ Test
568
- public void shouldUpdateUserSelective () {
569
- SqlSession sqlSession = sqlSessionFactory .openSession ();
570
- try {
566
+ void shouldUpdateUserSelective () {
567
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
571
568
Mapper mapper = sqlSession .getMapper (Mapper .class );
572
569
User user = new User ();
573
570
user .setId (999 );
@@ -579,16 +576,12 @@ public void shouldUpdateUserSelective() {
579
576
580
577
User loadedUser = mapper .getUser (999 );
581
578
assertEquals ("MyBatis" , loadedUser .getName ());
582
-
583
- } finally {
584
- sqlSession .close ();
585
579
}
586
580
}
587
581
588
582
@ Test
589
- public void mapperGetByEntity () {
590
- SqlSession sqlSession = sqlSessionFactory .openSession ();
591
- try {
583
+ void mapperGetByEntity () {
584
+ try (SqlSession sqlSession = sqlSessionFactory .openSession ()) {
592
585
Mapper mapper = sqlSession .getMapper (Mapper .class );
593
586
User query = new User ();
594
587
query .setName ("User4" );
@@ -600,8 +593,6 @@ public void mapperGetByEntity() {
600
593
query .setId (1 );
601
594
query .setName ("User4" );
602
595
assertEquals (0 , mapper .getByEntity (query ).size ());
603
- } finally {
604
- sqlSession .close ();
605
596
}
606
597
}
607
598
@@ -621,6 +612,7 @@ interface DatabaseIdMapper {
621
612
@ SelectProvider (type = SqlProvider .class )
622
613
String selectDatabaseId ();
623
614
615
+ @ SuppressWarnings ("unused" )
624
616
class SqlProvider {
625
617
public static String provideSql (ProviderContext context ) {
626
618
if ("hsql" .equals (context .getDatabaseId ())) {
0 commit comments